diff --git a/README.md b/README.md index ef03755..46ba30a 100644 --- a/README.md +++ b/README.md @@ -66,14 +66,12 @@ w := os.Stderr logger := slog.New( tint.NewHandler(w, &tint.Options{ ReplaceAttr: func(groups []string, a slog.Attr) slog.Attr { - err, ok := a.Value.Any().(error) - if !ok { - return a + if err, ok := a.Value.Any().(error); ok { + aErr := tint.Err(err) + aErr.Key = a.Key + return aErr } - - aErr = tint.Err(err) - aErr.Key = a.Key - return aErr + return a }, }), ) diff --git a/handler.go b/handler.go index bc077f4..e235378 100644 --- a/handler.go +++ b/handler.go @@ -32,14 +32,12 @@ Create a new logger that writes all errors in red: logger := slog.New( tint.NewHandler(w, &tint.Options{ ReplaceAttr: func(groups []string, a slog.Attr) slog.Attr { - err, ok := a.Value.Any().(error) - if !ok { - return a + if err, ok := a.Value.Any().(error); ok { + aErr := tint.Err(err) + aErr.Key = a.Key + return aErr } - - aErr = tint.Err(err) - aErr.Key = a.Key - return aErr + return a }, }), )