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 "slog.KindErr" and "slog.Err" Attrs Helper Function #63547
Comments
CC @jba |
Is this just syntax sugar for |
No, it's not just syntax sugar. It introduces a new Value Kind |
I think it's syntactic sugar for Handlers can distinguish errors with a type assertion. Adding a kind doesn't really do much; the Kinds are there to distinguish the various ways that |
While it's possible to manually distinguish value types through type assertions, this approach can lead to a degree of ambiguity and inconsistency in log entries. The It's worth noting that if we follow the logic that every value type can be distinguished by assertion, one could argue that we don't need The introduction of |
How does it make it more clear? I argued that seeing the How does it make it more consistent? If you'd proposed a canonical key for errors, like we have for message, level and time, then I'd see how that would help consistency. How does adding
but that's not actually the purpose of the different Kinds, and even if it were I don't quite see the argument for consistency.
That is absolutely true. |
OK, I understood, Thank you for your feedback. |
Abstract
This proposal suggests adding a dedicated error type,
slog.KindErr
, and a helper function,slog.Err
, to the "log/slog" package. These additions aim to improve structured error logging by providing a clear and efficient mechanism to distinguish and include errors in log entries.Proposal
slog.KindErr
add a new type,
slog.KindErr
, for representing errors in structured log entries. This type will enhance the distinction of errors from other attributes.slog.Err
Helper FunctionAdd a helper function,
slog.Err
, for simplifying the process of logging errors as structured attributes. This function will accept a message and an error, creating aslog.KindErr
attribute in the log entry.Usage
Developers can use slog.Err to conveniently log errors:
This approach ensures that error attributes are clearly distinguished from other key-value pairs.
The text was updated successfully, but these errors were encountered: