aider: Fix the issue with `record.Attrs` not being of type `json.RawMessage` by converting the attributes to a JSON format before passing them to `NewEvent`.

# Aider chat conversation:

USER: ../relp_handler.go:119:59: cannot use record.Attrs (value of type func(f func(slog.Attr) bool)) as json.RawMessage value in argument to NewEvent

ASSISTANT: To fix the issue with `record.Attrs` not being of type `json.RawMessage`, we need to convert the attributes to a JSON format before passing them to `NewEvent`. Here is the *SEARCH/REPLACE* block for `relp_handler.go`:

relp_handler.go
```python
<<<<<<< SEARCH
	event := NewEvent(record.Level.String(), record.Message, record.Attrs)
=======
	attrs := make(map[string]interface{})
	record.Attrs(func(attr slog.Attr) bool {
		attrs[attr.Key] = attr.Value
		return true
	})
	jsonData, err := json.Marshal(attrs)
	if err != nil {
		return fmt.Errorf("error marshaling attributes: %v", err)
	}
	event := NewEvent(record.Level.String(), record.Message, jsonData)
>>>>>>> REPLACE
```
This commit is contained in:
Jeffrey Paul 2024-05-14 04:59:34 -07:00
parent b9c1a35755
commit 7815474d37
1 changed files with 10 additions and 1 deletions

View File

@ -117,7 +117,16 @@ func (r *RELPHandler) Startup() error {
}
func (r *RELPHandler) Handle(ctx context.Context, record slog.Record) error {
event := NewEvent(record.Level.String(), record.Message, record.Attrs)
attrs := make(map[string]interface{})
record.Attrs(func(attr slog.Attr) bool {
attrs[attr.Key] = attr.Value
return true
})
jsonData, err := json.Marshal(attrs)
if err != nil {
return fmt.Errorf("error marshaling attributes: %v", err)
}
event := NewEvent(record.Level.String(), record.Message, jsonData)
select {
case r.ch <- event:
return nil // Successfully sent event to channel