Skip to content

Commit

Permalink
simplified example
Browse files Browse the repository at this point in the history
  • Loading branch information
lmittmann committed Sep 10, 2024
1 parent c67ac01 commit 7c923ea
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
}),
)
Expand Down
12 changes: 5 additions & 7 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
}),
)
Expand Down

0 comments on commit 7c923ea

Please sign in to comment.