-
Notifications
You must be signed in to change notification settings - Fork 18k
log/slog: Logger.With loses handler #73057
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
With corresponds to WithAttrs in the Handler interface: https://pkg.go.dev/log/slog#Handler Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only. For questions please refer to https://github.com/golang/go/wiki/Questions |
@seankhliao I absolutely appreciate curt answers, but the docs don't convey this. They suggest a logger with additional attributes, not a default logger with attributes. That this may be similar to the handler is absolutely not clear. Also Please reopen. Thank you! |
I understand why this happens but it should be mentioned in the documentation of |
What should the doc for I think the warning about embedding one handler in another should be in https://github.com/golang/example/blob/master/slog-handler-guide/README.md, and also a reference to that doc should appear in the doc for slog.Handler, not just the package doc. |
Also, testing/slogtest should catch this problem. Does it? |
Change https://go.dev/cl/661015 mentions this issue: |
Change https://go.dev/cl/660956 mentions this issue: |
There's a link in the package doc, but there should be one here too. For #73057. Change-Id: I8f8fe73f20bb6dd49cdf23b5f7634a92d4f7add9 Reviewed-on: https://go-review.googlesource.com/c/go/+/661015 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Sean Liao <sean@liao.dev> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
For golang/go#73057. Change-Id: Id9ee1c0af03f9b49f6063aa946b6fe5cfbc02483 Reviewed-on: https://go-review.googlesource.com/c/example/+/660956 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Consider this play: https://play.golang.com/p/wqZSGx6tIXi
What did you expect to see?
A logger created with custom handler like
should maintain this handler when creating a derived logger with
What did you see instead?
Deriving an
slog.Logger
usinglogger.With(...)
loses the loggers handler. Instead, a defaultslog.TextHandler
is assigned.This is surprising and not documented: https://pkg.go.dev/log/slog#Logger.With.
The text was updated successfully, but these errors were encountered: