-
Notifications
You must be signed in to change notification settings - Fork 95
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
Add ErrorRef
wrapper
#327
Add ErrorRef
wrapper
#327
Conversation
This commit adds the `ErrorRef` wrapper type. It enables to log error by reference, without moving ownership. It means that it is the non-owning counterpart of `ErrorValue`. Logging error references is an important use case for transparent logging middlewares. With this wrapper type, you can log the error and still pass it up the call stack. Such a wrapper type could already easily be implemented in user applications, but having it as part of Slog should help ergonomics. This also enables further improvements by integrating it with the Slog macros. Closes slog-rs#288
Unfortunately this does not support |
Thank you! Sorry for the delayed review. I will either open an issue or add a test for supporting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is good enough for publication. I'll maybe make one or two changes/comments.
key: Key, | ||
serializer: &mut dyn Serializer, | ||
) -> Result { | ||
serializer.emit_error(key, self.0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should add an emit_error_ref
method with a default implementation?
It is unfortunate we have the 'static
bound, but that's probably a requirement for things like slog_async
. An alternative would be using format_args!
and emit_arguments
, but that would loose information 😦.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point, may be worth adding it in the future
This commit adds the
ErrorRef
wrapper type. It enables to log error by reference, without moving ownership. It means that it is the non-owning counterpart ofErrorValue
.Logging error references is an important use case for transparent logging middlewares. With this wrapper type, you can log the error and still pass it up the call stack.
Such a wrapper type could already easily be implemented in user applications, but having it as part of Slog should help ergonomics. This also enables further improvements by integrating it with the Slog macros.
Closes #288
Make sure to: