From f3287611c9963eca227fb62052f02b767cb39163 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 6 Jan 2025 23:51:42 +0000 Subject: [PATCH] Bump github.com/lmittmann/tint from 1.0.5 to 1.0.6 Bumps [github.com/lmittmann/tint](https://github.com/lmittmann/tint) from 1.0.5 to 1.0.6. - [Release notes](https://github.com/lmittmann/tint/releases) - [Commits](https://github.com/lmittmann/tint/compare/v1.0.5...v1.0.6) --- updated-dependencies: - dependency-name: github.com/lmittmann/tint dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 +- vendor/github.com/lmittmann/tint/README.md | 17 +++++++++ vendor/github.com/lmittmann/tint/handler.go | 42 ++++++++++++++++----- vendor/modules.txt | 2 +- 5 files changed, 53 insertions(+), 14 deletions(-) diff --git a/go.mod b/go.mod index 39c7ca1c2..3fe77c43d 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/klauspost/compress v1.17.11 github.com/klauspost/pgzip v1.2.6 github.com/libp2p/go-buffer-pool v0.1.0 - github.com/lmittmann/tint v1.0.5 + github.com/lmittmann/tint v1.0.6 github.com/mattn/go-isatty v0.0.20 github.com/pelletier/go-toml/v2 v2.2.3 github.com/pquerna/ffjson v0.0.0-20190930134022-aa0246cd15f7 diff --git a/go.sum b/go.sum index 616a4cc17..3168df632 100644 --- a/go.sum +++ b/go.sum @@ -175,8 +175,8 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0 github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/libp2p/go-buffer-pool v0.1.0 h1:oK4mSFcQz7cTQIfqbe4MIj9gLW+mnanjyFtc6cdF0Y8= github.com/libp2p/go-buffer-pool v0.1.0/go.mod h1:N+vh8gMqimBzdKkSMVuydVDq+UV5QTWy5HSiZacSbPg= -github.com/lmittmann/tint v1.0.5 h1:NQclAutOfYsqs2F1Lenue6OoWCajs5wJcP3DfWVpePw= -github.com/lmittmann/tint v1.0.5/go.mod h1:HIS3gSy7qNwGCj+5oRjAutErFBl4BzdQP6cJZ0NfMwE= +github.com/lmittmann/tint v1.0.6 h1:vkkuDAZXc0EFGNzYjWcV0h7eEX+uujH48f/ifSkJWgc= +github.com/lmittmann/tint v1.0.6/go.mod h1:HIS3gSy7qNwGCj+5oRjAutErFBl4BzdQP6cJZ0NfMwE= github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4= github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I= github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= diff --git a/vendor/github.com/lmittmann/tint/README.md b/vendor/github.com/lmittmann/tint/README.md index 88a77acb4..46ba30a6b 100644 --- a/vendor/github.com/lmittmann/tint/README.md +++ b/vendor/github.com/lmittmann/tint/README.md @@ -60,6 +60,23 @@ logger := slog.New( ) ``` +```go +// create a new logger that writes all errors in red +w := os.Stderr +logger := slog.New( + tint.NewHandler(w, &tint.Options{ + ReplaceAttr: func(groups []string, a slog.Attr) slog.Attr { + if err, ok := a.Value.Any().(error); ok { + aErr := tint.Err(err) + aErr.Key = a.Key + return aErr + } + return a + }, + }), +) +``` + ### Automatically Enable Colors Colors are enabled by default and can be disabled using the `Options.NoColor` diff --git a/vendor/github.com/lmittmann/tint/handler.go b/vendor/github.com/lmittmann/tint/handler.go index d54b5d7a6..878dfa1cb 100644 --- a/vendor/github.com/lmittmann/tint/handler.go +++ b/vendor/github.com/lmittmann/tint/handler.go @@ -12,6 +12,8 @@ Options.ReplaceAttr can be used to alter or drop attributes. If set, it is called on each non-group attribute before it is logged. See [slog.HandlerOptions] for details. +Create a new logger that doesn't write the time: + w := os.Stderr logger := slog.New( tint.NewHandler(w, &tint.Options{ @@ -24,6 +26,22 @@ See [slog.HandlerOptions] for details. }), ) +Create a new logger that writes all errors in red: + + w := os.Stderr + logger := slog.New( + tint.NewHandler(w, &tint.Options{ + ReplaceAttr: func(groups []string, a slog.Attr) slog.Attr { + if err, ok := a.Value.Any().(error); ok { + aErr := tint.Err(err) + aErr.Key = a.Key + return aErr + } + return a + }, + }), + ) + # Automatically Enable Colors Colors are enabled by default and can be disabled using the Options.NoColor @@ -335,7 +353,14 @@ func (h *handler) appendAttr(buf *buffer, attr slog.Attr, groupsPrefix string, g return } - if attr.Value.Kind() == slog.KindGroup { + switch attr.Value.Kind() { + case slog.KindAny: + if err, ok := attr.Value.Any().(tintError); ok { + h.appendTintError(buf, err, attr.Key, groupsPrefix) + buf.WriteByte(' ') + return + } + case slog.KindGroup: if attr.Key != "" { groupsPrefix += attr.Key + "." groups = append(groups, attr.Key) @@ -343,15 +368,12 @@ func (h *handler) appendAttr(buf *buffer, attr slog.Attr, groupsPrefix string, g for _, groupAttr := range attr.Value.Group() { h.appendAttr(buf, groupAttr, groupsPrefix, groups) } - } else if err, ok := attr.Value.Any().(tintError); ok { - // append tintError - h.appendTintError(buf, err, attr.Key, groupsPrefix) - buf.WriteByte(' ') - } else { - h.appendKey(buf, attr.Key, groupsPrefix) - h.appendValue(buf, attr.Value, true) - buf.WriteByte(' ') + return } + + h.appendKey(buf, attr.Key, groupsPrefix) + h.appendValue(buf, attr.Value, true) + buf.WriteByte(' ') } func (h *handler) appendKey(buf *buffer, key, groups string) { @@ -395,7 +417,7 @@ func (h *handler) appendValue(buf *buffer, v slog.Value, quote bool) { } } -func (h *handler) appendTintError(buf *buffer, err error, attrKey, groupsPrefix string) { +func (h *handler) appendTintError(buf *buffer, err tintError, attrKey, groupsPrefix string) { buf.WriteStringIf(!h.noColor, ansiBrightRedFaint) appendString(buf, groupsPrefix+attrKey, true) buf.WriteByte('=') diff --git a/vendor/modules.txt b/vendor/modules.txt index ac689415d..31cd43074 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -356,7 +356,7 @@ github.com/kylelemons/godebug/pretty # github.com/libp2p/go-buffer-pool v0.1.0 ## explicit; go 1.17 github.com/libp2p/go-buffer-pool -# github.com/lmittmann/tint v1.0.5 +# github.com/lmittmann/tint v1.0.6 ## explicit; go 1.21 github.com/lmittmann/tint # github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0