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
proposal: log/slog: Add WithAttrs and Logger.WithAttrs #66937
Comments
This merge request introduces the WithAttrs function to the log/slog package, enabling efficient attribute-based logging of structured data. Updates golang#66937
Change https://go.dev/cl/580495 mentions this issue: |
CC @jba |
It's unfortunate that you can't write
That is less efficient, but the question is whether it comes up often enough to matter. |
While the suggested workaround using a loop to iterate over the attributes and apply them individually with Considering your point about whether the inefficiency of the loop comes up often enough to matter, I think it's important. However, introducing a dedicated function like |
Just as LogAttrs offers a specialized solution for logging structured data with attributes, a dedicated WithAttrs function would serve a similar purpose for attribute-based logging within the context of With. |
Proposal Details
This proposal addresses a deficiency in the log/slog package, specifically the lack of support for purely attribute-based logging functions/methods. The primary focus of this proposal is the introduction of a new function, WithAttrs, to both the package scope and the Logger interface. This addition seeks to streamline and enhance logging practices, particularly in scenarios such as:
The text was updated successfully, but these errors were encountered: