From eb6157d5a62d8d071096b89af92e1a0ab2daca16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sedl=C3=A1=C4=8Dek?= Date: Wed, 23 Aug 2023 13:27:51 +0200 Subject: [PATCH] Error type (#4) * Error type checker * Update README.md --- README.md | 2 +- devslog.go | 7 +++++++ 2 files changed, 8 insertions(+), 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` 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