-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
log/slog: arg to Record.Attrs should return bool #59060
Comments
Returning a bool is also useful if the Handler wants to look for a particular Attr. For example, some handlers might want to extract an error if there is one and treat it specially. /cc @ianthehat Original proposal: #56345 |
Yes, my use cases were things like detecting a specific attribute key to indicate a message type (operating like a mux to underlying handlers), and detecting specific error types to filter out messages that were not interesting. In both cases the attribute in question will be first by convention, but I have to scan the whole list anyway using |
This proposal has been added to the active column of the proposals project |
Based on the discussion above, this proposal seems like a likely accept. |
Change https://go.dev/cl/484096 mentions this issue: |
No change in consensus, so accepted. 🎉 |
Record.Attrs stops as soon as its argument function returns false. Fixes golang#59060. Change-Id: I578d64635e0e52b0fcdbc57f6d5a27a6efac8c70 Reviewed-on: https://go-review.googlesource.com/c/go/+/484096 TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Alan Donovan <[email protected]> Run-TryBot: Jonathan Amsterdam <[email protected]>
Record.Attrs stops as soon as its argument function returns false. Fixes golang#59060. Change-Id: I578d64635e0e52b0fcdbc57f6d5a27a6efac8c70 Reviewed-on: https://go-review.googlesource.com/c/go/+/484096 TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Alan Donovan <[email protected]> Run-TryBot: Jonathan Amsterdam <[email protected]>
The
Record.Attrs
method currently accepts an argument of typefunc(Attr)
.For future consistency with iteration over func values, it should accept
func(Attr) bool
.The text was updated successfully, but these errors were encountered: