Last active
January 25, 2025 18:51
-
-
Save mxxntype/a1bbebbb7d7efcc04c23ba0db1b73a61 to your computer and use it in GitHub Desktop.
A snippet of using eyre::Report
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use color_eyre::eyre::Report; | |
| fn main() -> Result<(), Report> { | |
| color_eyre::install()?; | |
| install_tracing()?; | |
| let int = 512; | |
| let string = "sample"; | |
| tracing::info!(?int, ?string, "Sample log message"); | |
| Ok(()) | |
| } | |
| fn install_tracing() -> Result<(), Report> { | |
| use tracing_error::ErrorLayer; | |
| use tracing_subscriber::prelude::*; | |
| use tracing_subscriber::{fmt, EnvFilter}; | |
| let filter_layer = EnvFilter::try_from_default_env().or_else(|_| EnvFilter::try_new("info"))?; | |
| let format_layer = fmt::layer() | |
| .with_target(false) | |
| .without_time() | |
| .with_writer(std::io::stderr); | |
| tracing_subscriber::registry() | |
| .with(filter_layer) | |
| .with(format_layer) | |
| .with(ErrorLayer::default()) | |
| .try_init()?; | |
| Ok(()) | |
| } |
Author
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
User-facing errors look like this: