Hacker News new | ask | show | jobs
by onionisafruit 1095 days ago
Indeed it's in "golang.org/x/exp/slog"
1 comments

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"
That 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.
Put the logger in the context
Isn't it considered bad practice?
yes, 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

> opentelemetry is basically a house of antipatterns

"Look on My Works Ye Mighty and Despair!"

https://github.com/open-telemetry/opentelemetry-collector/tr... -> 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.
I don't enjoy the otel APIs, but they are implicitly scoped; contexts are a natural place to store them.
"The context stores request-scoped data" might be another Go-team dogma due for course correction RSN.
It's already idiomatic for OpenTelemetry, and otel has use cases that overlap slog.