6 ms·
I wonder if it's possible to use slog in 1.20 already, is there a back-port? I'm changing logging on the service right now and it just makes sense to use it no
by vl 3y ago
I wonder if it's possible to use slog in 1.20 already, is there a back-port?
I'm changing logging on the service right now and it just makes sense to use it now, but entire service can't move to pre-release version of go.
- onionisafruit 3y agoIndeed it's in "golang.org/x/exp/slog"
- mdaniel 3y agohttps://pkg.go.dev/golang.org/x/exp/slog#hdr-Levels https://pkg.go.dev/golang.org/x/exp/slog#hdr-Levels seems to fall into the same trap that drives me _starkraving_ about the 18,000 different(!) golang logging packages: there doesn't seem to be a sane way of influencing the log level at runtime if the author doesn't have the foresight/compassion to add a command-line flag or env-var to influence it. A similar complaint about the "haha I log json except this other dep that I import who logs using uber/zap so pffft if you try to parse stdout as json"
- onionisafruit 3y agoThat bugs me too. I consider it a red flag for a library to log to anything except a `log.Logger` passed in from the caller. Now I'll expand that to include a `slog.Logger` as well. If the library is logging directly to stderr or stdout, that is a sign that it probably has other design issues as well.
- lokar 3y agoPut the logger in the context
- vl 3y agoIsn't it considered bad practice?
- tptacek 3y agoIt's already idiomatic for OpenTelemetry, and otel has use cases that overlap slog.
- preseinger 3y agoyes, in general the context stores request-scoped data, whether or not the logger is a request-scoped value is a grey area and to reply to sibling comment, opentelemetry is basically a house of antipatterns, definitely do not look to it for guidance
- tptacek 3y agoI don't enjoy the otel APIs, but they are implicitly scoped; contexts are a natural place to store them.
- mdaniel 3y ago> opentelemetry is basically a house of antipatterns "Look on My Works Ye Mighty and Despair!" https://github.com/open-telemetry/opentelemetry-collector/tree/v0.80.0/cmd/builder#tldr https://github.com/open-telemetry/opentelemetry-collector/tr... -> https://github.com/open-telemetry/opentelemetry-collector-releases/blob/v0.80.0/distributions/otelcol-contrib/manifest.yaml https://github.com/open-telemetry/opentelemetry-collector-re... ... and then a reasonable person trying to load that mess into their head may ask 'err, what's the difference between go.opentelemetry.io/collector and github.com/open-telemetry/opentelemetry-collector-contrib?' $ curl -fsS go.opentelemetry.io/collector | grep go-import <meta name="go-import" content="go.opentelemetry.io/collector git https://github.com/open-telemetry/opentelemetry-collector"> Oh, I see. Thanks.
- euroderf 3y ago"The context stores request-scoped data" might be another Go-team dogma due for course correction RSN.