| Crates.io | tracing_log_error |
| lib.rs | tracing_log_error |
| version | 0.1.4 |
| created_at | 2025-01-20 17:35:56.692465+00 |
| updated_at | 2025-01-21 12:57:48.005214+00 |
| description | A set of helpers to capture rich error context in tracing logs |
| homepage | |
| repository | https://github.com/LukeMathWalker/tracing_log_error |
| max_upload_size | |
| id | 1524069 |
| size | 30,926 |
tracing_log_errorA utility crate to capture an error, and all its key error properties,
in a tracing event.
use tracing_log_error::log_error;
let e = std::io::Error::new(std::io::ErrorKind::Other, "My error");
log_error!(e, "The connection was dropped");
The log_error! invocation captures:
Display representation of the error, in the error.message field.Debug representation of the error, in the error.details field.error.source_chain field.Using raw tracing, the equivalent would be:
use tracing::{event, Level};
use tracing_log_error::fields;
let e = std::io::Error::new(std::io::ErrorKind::Other, "My error");
event!(
Level::ERROR,
error.message = fields::error_message(&e),
error.details = fields::error_details(&e),
error.source_chain = fields::error_source_chain(&e),
"The connection was dropped"
);
To use log_error!, add both tracing and tracing_log_error to your Cargo.toml:
[dependencies]
tracing = "0.1"
tracing-log-error = "0.1"
Error traitSome 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 tracing_log_error::log_error;
use anyhow::anyhow;
let e = anyhow!("Hey");
// Notice the `*` 👇
log_error!(*e, "An error occurred");
Check out log_error!'s documentation for more examples and details.
You can customize the log level, add custom fields, and more.