-
Notifications
You must be signed in to change notification settings - Fork 271
Description
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
and Debug
representations, and especially backtraces via the new Error::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.
trait Log {
...
// The record serves the purpose of providing the location, and optionally an additional error message / metadata.
// Question: Should the record be optional or required?
fn error(&self, error: &dyn std::error::Error, record: Option<&Record>);
}
Plus a macro.
Naming for that macro would of course be somewhat awkward, considering error!
exists. Maybe with_error!()
. Also there could be a variant of error!
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.