-
Notifications
You must be signed in to change notification settings - Fork 18k
log/slog: drop only completely empty Attrs #59282
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
This proposal has been added to the active column of the proposals project |
I think this is a good idea. After the decision was made to interpret an empty key as a "skip" attr I was wondering if that would cause problems with the |
Based on the discussion above, this proposal seems like a likely accept. |
Change https://go.dev/cl/484095 mentions this issue: |
No change in consensus, so accepted. 🎉 |
Specify that Handlers should ignore zero-valued Attrs. Implement that policy in the built-in handlers. Fixes golang#59282. Change-Id: I4430686b61f49bdac849ee300daaabfac9895849 Reviewed-on: https://go-review.googlesource.com/c/go/+/484095 Run-TryBot: Jonathan Amsterdam <jba@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Alan Donovan <adonovan@google.com>
Specify that Handlers should ignore zero-valued Attrs. Implement that policy in the built-in handlers. Fixes golang#59282. Change-Id: I4430686b61f49bdac849ee300daaabfac9895849 Reviewed-on: https://go-review.googlesource.com/c/go/+/484095 Run-TryBot: Jonathan Amsterdam <jba@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Alan Donovan <adonovan@google.com>
Currently, handlers are expected to drop attributes with an empty key (except for Groups), and the built-in handlers do so. I propose changing that convention: only an Attr whose key is empty and whose value is nil should be dropped.
@ianthehat pointed out to me that omitting the key but not the value could indicate a bug (for example, by using a variable for the key that unintentionally holds the empty string). One of slog's tenets is to display whatever it can—that's why we display mismatched key-value pairs instead of dropping them or failing—and the same argument applies here.
Most uses of this feature are probably in
ReplaceAttr
functions, where it is easy to make this change.Handlers can detect an empty Attr
a
witha.Equal(Attr{})
.See also #56345.
The text was updated successfully, but these errors were encountered: