From 31dcb3daa8c8ab14bdcf4946f904eb9db33f9cc2 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Wed, 22 Nov 2023 15:00:36 +0800 Subject: [PATCH] fix fmt.Stringer values in json handler --- log/handler.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/log/handler.go b/log/handler.go index 8d43a44736..d61ee452d4 100644 --- a/log/handler.go +++ b/log/handler.go @@ -213,7 +213,11 @@ func builtinReplace(_ []string, attr slog.Attr, logfmt bool) slog.Attr { attr.Value = slog.StringValue(v.Dec()) } case fmt.Stringer: - attr.Value = slog.StringValue(v.String()) + if v == nil || (reflect.ValueOf(v).Kind() == reflect.Pointer && reflect.ValueOf(v).IsNil()) { + attr.Value = slog.StringValue("") + } else { + attr.Value = slog.StringValue(v.String()) + } } return attr }