From 7c923ea37095d5e9f077392c7d1f83b364555c33 Mon Sep 17 00:00:00 2001 From: lmittmann Date: Tue, 10 Sep 2024 16:14:57 +0200 Subject: [PATCH] simplified example --- README.md | 12 +++++------- handler.go | 12 +++++------- 2 files changed, 10 insertions(+), 14 deletions(-) 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 }, }), )