From 29e2bf1ab0f22077476a24d2f328e6b2deb3be92 Mon Sep 17 00:00:00 2001 From: dimagolomozy Date: Thu, 16 May 2024 14:27:49 +0300 Subject: [PATCH] fix error printing --- slog_handler.go | 2 ++ slog_handler_test.go | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/slog_handler.go b/slog_handler.go index a0e2d7a..51ac2ec 100644 --- a/slog_handler.go +++ b/slog_handler.go @@ -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 { diff --git a/slog_handler_test.go b/slog_handler_test.go index b811011..840c9a5 100644 --- a/slog_handler_test.go +++ b/slog_handler_test.go @@ -1,6 +1,7 @@ package coralogix import ( + "errors" "fmt" "log/slog" "strings" @@ -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{}