Skip to content

Commit

Permalink
fix error printing
Browse files Browse the repository at this point in the history
  • Loading branch information
DimaGolomozy committed May 16, 2024
1 parent e2ca80a commit 29e2bf1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions slog_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ func (h *CoralogixHandler) Stop() {

func attrToMap(m map[string]any, a slog.Attr) {
switch v := a.Value.Any().(type) {
case error:
m[a.Key] = v.Error()
case []slog.Attr:
m2 := map[string]any{}
for _, a2 := range v {
Expand Down
7 changes: 5 additions & 2 deletions slog_handler_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package coralogix

import (
"errors"
"fmt"
"log/slog"
"strings"
Expand Down Expand Up @@ -29,10 +30,12 @@ func TestSlogHandler_AttrToMap(t *testing.T) {
m1 := map[string]any{}
attrToMap(m1, slog.String("1", "1"))
attrToMap(m1, slog.Int("2", 2))
attrToMap(m1, slog.Any("error", errors.New("test")))

assert.Equal(t, map[string]any{
"1": "1",
"2": int64(2),
"1": "1",
"2": int64(2),
"error": "test",
}, m1)

m2 := map[string]any{}
Expand Down

0 comments on commit 29e2bf1

Please sign in to comment.