Skip to content

Commit

Permalink
Error type (#4)
Browse files Browse the repository at this point in the history
* Error type checker

* Update README.md
  • Loading branch information
david-littlefarmer authored Aug 23, 2023
1 parent a002ce2 commit eb6157d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
`devslog` is zero dependency custom logging handler for Go's standard [`log/slog`](https://pkg.go.dev/log/slog) package that provides structured logging with colorful and indented structure for developing.

### Develop with this output
![image](https://github.com/golang-cz/devslog/assets/17728576/be0eca2c-192b-442f-b3c0-eecef107871a)
![image](https://github.com/golang-cz/devslog/assets/17728576/0bae7ec7-0513-41a4-9682-0e0fc74747e7)

### Instead of these outputs
`TextHandler`
Expand Down
7 changes: 7 additions & 0 deletions devslog.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,13 @@ func (h *developHandler) colorize(buf []byte, as attributes, level int, groups [
val = cs(val, fgCyan)
case slog.KindAny:
a := a.Value.Any()
err, isError := a.(error)
if isError {
mark = cs("E", fgRed)
val = csb(fmt.Sprintf(" %v ", err), fgBlack, bgRed)
break
}

jsonBytes, err := json.Marshal(a)
if err != nil {
break
Expand Down

0 comments on commit eb6157d

Please sign in to comment.