From e885b47be1c57dc9fa588fa53051ee92b46548cb Mon Sep 17 00:00:00 2001 From: david-littlefarmer Date: Wed, 23 Aug 2023 13:23:36 +0200 Subject: [PATCH 1/2] Error type checker --- devslog.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/devslog.go b/devslog.go index 0b8912a..a75c384 100644 --- a/devslog.go +++ b/devslog.go @@ -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 From e8493ea96f0673a6d418e6572000c31bf8ae3a14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sedl=C3=A1=C4=8Dek?= Date: Wed, 23 Aug 2023 13:25:58 +0200 Subject: [PATCH 2/2] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e354fe4..41524ca 100644 --- a/README.md +++ b/README.md @@ -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`