From 8172ba8a80275ea7c02377c53991ab2647a6964e Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 27 Jan 2025 07:46:34 +0000 Subject: [PATCH] fix(deps): update module github.com/tjhop/slog-gokit to v0.1.3 (#10520) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 +-- vendor/github.com/tjhop/slog-gokit/README.md | 13 ++++++- vendor/github.com/tjhop/slog-gokit/handler.go | 34 ++++++++++++++++--- vendor/modules.txt | 2 +- 5 files changed, 45 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index 74ccdfa31fa..ee6c5fc90b6 100644 --- a/go.mod +++ b/go.mod @@ -77,7 +77,7 @@ require ( github.com/prometheus/procfs v0.15.1 github.com/shirou/gopsutil/v4 v4.24.12 github.com/thanos-io/objstore v0.0.0-20250120094545-4b72edf06a59 - github.com/tjhop/slog-gokit v0.1.2 + github.com/tjhop/slog-gokit v0.1.3 github.com/twmb/franz-go v1.18.1 github.com/twmb/franz-go/pkg/kadm v1.14.0 github.com/twmb/franz-go/pkg/kfake v0.0.0-20250121044851-f30c518d6b72 diff --git a/go.sum b/go.sum index 2fd1411665b..8bb282bfabc 100644 --- a/go.sum +++ b/go.sum @@ -1725,8 +1725,8 @@ github.com/tencentyun/cos-go-sdk-v5 v0.7.40 h1:W6vDGKCHe4wBACI1d2UgE6+50sJFhRWU4 github.com/tencentyun/cos-go-sdk-v5 v0.7.40/go.mod h1:4dCEtLHGh8QPxHEkgq+nFaky7yZxQuYwgSJM87icDaw= github.com/thanos-io/objstore v0.0.0-20250120094545-4b72edf06a59 h1:baslL6W/++17WFDtNd/hXC3H9LUBqTd3mzU2iKwStPU= github.com/thanos-io/objstore v0.0.0-20250120094545-4b72edf06a59/go.mod h1:Quz9HUDjGidU0RQpoytzK4KqJ7kwzP+DMAm4K57/usM= -github.com/tjhop/slog-gokit v0.1.2 h1:pmQI4SvU9h4gA0vIQsdhJQSqQg4mOmsPykG2/PM3j1I= -github.com/tjhop/slog-gokit v0.1.2/go.mod h1:8fhlcp8C8ELbg3GCyKv06tgt4B5sDq2P1r2DQAu1HuM= +github.com/tjhop/slog-gokit v0.1.3 h1:6SdexP3UIeg93KLFeiM1Wp1caRwdTLgsD/THxBUy1+o= +github.com/tjhop/slog-gokit v0.1.3/go.mod h1:Bbu5v2748qpAWH7k6gse/kw3076IJf6owJmh7yArmJs= github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU= github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk= diff --git a/vendor/github.com/tjhop/slog-gokit/README.md b/vendor/github.com/tjhop/slog-gokit/README.md index d6b5e51de6e..6addd47981d 100644 --- a/vendor/github.com/tjhop/slog-gokit/README.md +++ b/vendor/github.com/tjhop/slog-gokit/README.md @@ -1,3 +1,8 @@ +[![license](https://img.shields.io/github/license/tjhop/slog-gokit)](https://github.com/tjhop/slog-gokit/blob/master/LICENSE) +[![Go Report Card](https://goreportcard.com/badge/github.com/tjhop/slog-gokit)](https://goreportcard.com/report/github.com/tjhop/slog-gokit) +[![golangci-lint](https://github.com/tjhop/slog-gokit/actions/workflows/golangci-lint.yaml/badge.svg)](https://github.com/tjhop/slog-gokit/actions/workflows/golangci-lint.yaml) +[![Latest Release](https://img.shields.io/github/v/release/tjhop/slog-gokit)](https://github.com/tjhop/slog-gokit/releases/latest) + # Go slog-gokit Adapter This library provides a custom slog.Handler that wraps a go-kit Logger, so that loggers created via `slog.New()` chain their log calls to the internal go-kit Logger. @@ -8,6 +13,12 @@ This library provides a custom slog.Handler that wraps a go-kit Logger, so that go get github.com/tjhop/slog-gokit ``` +## Documentation + +Documentation can be found here: + +https://pkg.go.dev/github.com/tjhop/slog-gokit + ## Example ```go @@ -29,7 +40,7 @@ func main() { slogger := slog.New(slgk.NewGoKitHandler(gklogger, nil)) slogger.WithGroup("example_group").With("foo", "bar").Info("hello world") - // The slog Logger produced logs at slog.LevelInfo by default. + // The slog Logger produces logs at slog.LevelInfo by default. // Optionally create an slog.Leveler to dynamically adjust the level of // the slog Logger. lvl := &slog.LevelVar{} diff --git a/vendor/github.com/tjhop/slog-gokit/handler.go b/vendor/github.com/tjhop/slog-gokit/handler.go index a926595292f..d2b84a647cd 100644 --- a/vendor/github.com/tjhop/slog-gokit/handler.go +++ b/vendor/github.com/tjhop/slog-gokit/handler.go @@ -41,6 +41,8 @@ func NewGoKitHandler(logger log.Logger, level slog.Leveler) slog.Handler { return &GoKitHandler{logger: logger, level: level} } +// Enabled returns true if the internal slog.Leveler is enabled for the +// provided log level. It implements slog.Handler. func (h *GoKitHandler) Enabled(_ context.Context, level slog.Level) bool { if h.level == nil { h.level = &slog.LevelVar{} // Info level by default. @@ -49,6 +51,10 @@ func (h *GoKitHandler) Enabled(_ context.Context, level slog.Level) bool { return level >= h.level.Level() } +// Handler take an slog.Record created by an slog.Logger and dispatches the log +// call to the internal go-kit logger. Groups and attributes created by slog +// are formatted and added to the log call as individual key/value pairs. It +// implements slog.Handler. func (h *GoKitHandler) Handle(_ context.Context, record slog.Record) error { if h.logger == nil { h.logger = defaultGoKitLogger @@ -77,6 +83,8 @@ func (h *GoKitHandler) Handle(_ context.Context, record slog.Record) error { return logger.Log(pairs...) } +// WithAttrs formats the provided attributes and caches them in the handler to +// attach to all future log calls. It implements slog.Handler. func (h *GoKitHandler) WithAttrs(attrs []slog.Attr) slog.Handler { pairs := make([]any, 0, 2*len(attrs)) for _, a := range attrs { @@ -95,6 +103,8 @@ func (h *GoKitHandler) WithAttrs(attrs []slog.Attr) slog.Handler { } } +// WithGroup sets the group prefix string and caches it within the handler to +// use to prefix all future log attribute pairs. It implements slog.Handler. func (h *GoKitHandler) WithGroup(name string) slog.Handler { if name == "" { return h @@ -120,11 +130,25 @@ func appendPair(pairs []any, groupPrefix string, attr slog.Attr) []any { switch attr.Value.Kind() { case slog.KindGroup: - if attr.Key != "" { - groupPrefix = groupPrefix + "." + attr.Key - } - for _, a := range attr.Value.Group() { - pairs = appendPair(pairs, groupPrefix, a) + attrs := attr.Value.Group() + if len(attrs) > 0 { + // Only process groups that have non-empty attributes + // to properly conform to slog.Handler interface + // contract. + + if attr.Key != "" { + // If a group's key is empty, attributes should + // be inlined to properly conform to + // slog.Handler interface contract. + if groupPrefix != "" { + groupPrefix = groupPrefix + "." + attr.Key + } else { + groupPrefix = attr.Key + } + } + for _, a := range attrs { + pairs = appendPair(pairs, groupPrefix, a) + } } default: key := attr.Key diff --git a/vendor/modules.txt b/vendor/modules.txt index 3a235fc5b86..1709bad6d84 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1187,7 +1187,7 @@ github.com/thanos-io/objstore/providers/gcs github.com/thanos-io/objstore/providers/s3 github.com/thanos-io/objstore/providers/swift github.com/thanos-io/objstore/tracing/opentracing -# github.com/tjhop/slog-gokit v0.1.2 +# github.com/tjhop/slog-gokit v0.1.3 ## explicit; go 1.21 github.com/tjhop/slog-gokit # github.com/tklauser/go-sysconf v0.3.12