Update log/handler.go

Co-authored-by: Martin Holst Swende <martin@swende.se>
This commit is contained in:
jwasinger 2023-11-09 18:57:10 +08:00 committed by Jared Wasinger
parent 3e11e89d57
commit bd684ceac7

View file

@ -197,9 +197,8 @@ func LogfmtHandlerWithLevel(wr io.Writer, level slog.Level) slog.Handler {
func builtinReplace(_ []string, attr slog.Attr) slog.Attr { func builtinReplace(_ []string, attr slog.Attr) slog.Attr {
switch attr.Key { switch attr.Key {
case slog.TimeKey: case slog.TimeKey:
if t, ok := attr.Value.Any().(time.Time); ok { if attr.Value.Kind() == slog.KindTime {
attr = slog.Any("t", t.Format(timeFormat)) return slog.Time("t", attr.Value.Time())
return attr
} }
case slog.LevelKey: case slog.LevelKey:
if l, ok := attr.Value.Any().(slog.Level); ok { if l, ok := attr.Value.Any().(slog.Level); ok {