From 88f9530a88d5e18a001d701b6317dd7cdddf36ac Mon Sep 17 00:00:00 2001 From: lmittmann <3458786+lmittmann@users.noreply.github.com> Date: Thu, 18 Jan 2024 23:04:17 +0100 Subject: [PATCH] Fixed struct attribute name output (#57) * added field name test case * fixed field name output --------- Co-authored-by: lmittmann --- handler.go | 2 +- handler_test.go | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/handler.go b/handler.go index 0cc3190..62d153c 100644 --- a/handler.go +++ b/handler.go @@ -390,7 +390,7 @@ func (h *handler) appendValue(buf *buffer, v slog.Value, quote bool) { case *slog.Source: h.appendSource(buf, cv) default: - appendString(buf, fmt.Sprint(v.Any()), quote) + appendString(buf, fmt.Sprintf("%+v", v.Any()), quote) } } } diff --git a/handler_test.go b/handler_test.go index 5000e4a..8e710fd 100644 --- a/handler_test.go +++ b/handler_test.go @@ -335,6 +335,15 @@ func TestHandler(t *testing.T) { }, Want: `Nov 10 23:00:00.000 ERR test group.err=fail`, }, + { // https://github.com/lmittmann/tint/issues/55 + F: func(l *slog.Logger) { + l.Info("test", "key", struct { + A int + B *string + }{A: 123}) + }, + Want: `Nov 10 23:00:00.000 INF test key="{A:123 B:}"`, + }, } for i, test := range tests {