-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: log/slog: add an 'error' field to 'Record' #59364
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
It may be discussed in #56345, and removed. |
Record has never had an Error field. What was removed in previous discussions was a public ErrorKey, which this proposal does Not reintroduce. |
This would be really nice. After coming from Logrus and Zap, I find myself missing a I have currently have a wrapper like this in every project using slog:
|
We discussed this on the main proposal and decided against it. Representative comment: #56345 (comment). |
Disappointing. I can see the argument, but I think it fails to take the broader perspective of the importance of error content (as opposed to other structured content) and third-party libraries. I was excited about the prospect of pulling in a library that uses slog and not needing to write a logger or transform entries. While this might still be necessary for some use cases, it sure would have been nice to a least have errors work out of the box. |
Record contains Time, Level, and Message, which lets the handler decide what to use for keys for those. This proposal does not force a key on anyone. |
True, it doesn't export a key. But another way to look at it is that the For that matter, anyone could look for a value of type Which brings up a question: how would your proposal handle multiple errors in a log call? |
I would say that the most recent error would be kept (ie: calling WithErr replaces any previous error). |
We just removed the special casing of errors from slog.Err (vs slog.Info etc). It doesn't seem like it makes sense to add a special case for errors back. |
This proposal has been added to the active column of the proposals project |
I can be confusing if we have a record at error level with Err nil or a record not at error level but with an Err value. |
I don't think that is related to this proposal. You can have an error level log, without an You can have a non-error level log (such as debug level or warn level) that does include an |
But what if I want the last one? Or both? My point is, I think it's too limiting to have a |
Based on the discussion above, this proposal seems like a likely decline. |
No change in consensus, so declined. |
My conclusion from reading the original
This seems like a valid point, I personally have never had the need to do anything much different than using my own custom
Since the current proposal already leaves you to implement this yourself/ to write your own error attr in some way or form, why wouldn't the multiple errors be treated the same? I'd argue that the case for multiple errors can be treated like error attribute is treated at the moment, write your own solution for handling them (eg writing your own Error attribute also does not tie the implementation to any logging level, so you're free to mix and match. Having said all of that, I do agree that the error attribute does not have a clear cut solution like the others, but I cannot help but feel like I am hacking and piecing together what I would expect to be part of the library when writing my own error attributes, especially since I have to put it in some module and reach out for it every time, even though I have Please do correct me, and tell me if I am missing something, but this has been nagging me ever since I tried I tried the library some while ago. Can anyone point me to the current recommendation on how to approach error logging within the current iteration of the |
This proposal is to discuss adding an
error
field toRecord
, and potentially adding associated methods toslog
andLogger
.Example adding
error
toRecord
:Possible new methods:
Advantages of doing this proposal:
Other comments:
error
types:With this proposal, the handler would choose what the key is, or if there even is a key.
This puts control back where it should be for something as important as errors.
If the log aggregation system I am using wants messages or errors to come in with a specific key or in a specific format, I can accomodate that with a custom handler.
This lets me have consistent logs, even for libraries and sub-libraries. Like this:
thanks,
Chris
#56345 and @jba
The text was updated successfully, but these errors were encountered: