tracing_log_error
A utility crate to capture an error, and all its key error properties,
in a tracing event.
use log_error;
let e = new;
log_error!;
The log_error! invocation captures:
- The
Displayrepresentation of the error, in theerror.messagefield. - The
Debugrepresentation of the error, in theerror.detailsfield. - The chain of error sources, in the
error.source_chainfield.
Using raw tracing, the equivalent would be:
use ;
use fields;
let e = new;
event!;
Installation
To use log_error!, add both tracing and tracing_log_error to your Cargo.toml:
[]
= "0.1"
= "0.1"
Some errors don't implement the Error trait
Some common error reporting types, like anyhow::Error or eyre::Report
or Box<dyn std::error::Error>, don't implement the Error trait.
If you try to use log_error! with them directly, you'll get a compiler error.
Good news: you can still use log_error! with them!
They dereference to a type that implements the Error trait, so you can
use * to dereference them when passing them to log_error!:
use log_error;
use anyhow;
let e = anyhow!;
// Notice the `*` 👇
log_error!;
Advanced usage
Check out log_error!'s documentation for more examples and details.
You can customize the log level, add custom fields, and more.