-
Notifications
You must be signed in to change notification settings - Fork 259
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
Logging std::error::Errors #357
Comments
Personally, I think treating errors as first-class concepts in logs is a worthwhile thing to do. It looks like we might not have given this too much thought in the past, but now that the We could add something like a error!(source: err, "Something didn't work {}", err); Alternatively we could design support into the key-values API and leave it up to convention to capture an error with a common key name. That would probably be my preferred approach, because it would avoid creating too many parallel syntaxes in the |
I like the The ability to log an error without providing an additional message would also be nice though. |
Yep, I definitely agree that it makes sense to allow Errors to be tacked onto log records - it will be a field that's only available with the |
I thought a missing How is that dealt with in, eg, |
I've explicitly mentioned that Send and Sync is something to consider for the future, but I don't think anyone followed up on that. In I think it is worthwhile to investigate and built an async logger for For reference: https://github.com/slog-rs/async/blob/e33823ceb8e7af9e0874262e1e57845bd5f30249/lib.rs#L448 |
This seems reasonable approach that could be done without additional support from the |
We're on board with adding specific support for For There is some space to explore about macro support though. I think all log levels should support accepting an error, because not every error you encounter is necessarily an error-worthy log. You might want to log them as warnings or debug if they're non-critical. We could follow the same approach as if let Err(e) = fallible() {
debug!(error: e, "it didn't work, but that's ok");
debug!(target: "something", error: e, "it didn't work, but that's ok");
error!(error: e, "it didn't work");
error!(target: "something", error: e, "it didn't work");
// Could use `err` instead of `error`
error!(err: e, "it didn't work");
// Would we also want this to work?
error!(err: e);
} |
We are looking at adding error logging inside AWS Lambda Runtime for Rust (awslabs/aws-lambda-rust-runtime#241). The plan was to use Display trait, but that means the user would have to implement it, potentially more than once. Having a standard way of logging Looks like the work on this issue stalled. |
Could some of this now be handled with log's builtin structured logging interfaces? |
Hey @rimutaka 👋 The blocker for error!(source: e, “Oh no!”); we could cobble that in with some liberal duplication to the macros, but would be better off converting There’s nothing blocking support in the unstable structured API, like @softprops mentioned. We could add |
The latter seems to keep the surface area small.
|
@softprops That would be much nicer, but we've had trouble in the past attempting to wrangle new syntax into the macros, especially after the message string, because currently that whole lot is shelled straight off to Until we can come up with entirely new macros (I've been prototyping some stuff in this repo) I think we'll have to attach the error at the front, before the message. |
Heads up: I've recently contributed |
@Kixunil No sweat! It looks like the |
That's great! I don't follow |
It would be really nice to have a specialized way of logging errors that implement
std::error::Error
.This would allow automatically capturing detailed information about an error, including the
Display
andDebug
representations, and especially backtraces via the newError::backtrace
, which has an open PR.The main purpose is to give the backend implementation the option to extract all desired information about an error and use it as appropriate for the output.
Not sure how this could fit into the current design, but I'd imagine an additional method on
Log
and a macro.Plus a macro.
Naming for that macro would of course be somewhat awkward, considering
error!
exists. Maybewith_error!()
. Also there could be a variant oferror!
that allows specifying an error value.One could of course ask if this is really necessary, since you could already write a custom macro or method that captures the required information as a
Record
. But I'd like to see a standardized way of doing this that gives the logger implementation the power to do what it wants, without forcing the user to make a decision here up-front.The text was updated successfully, but these errors were encountered: