Skip to content

Instantly share code, notes, and snippets.

@mxxntype
Last active January 25, 2025 18:51
Show Gist options
  • Select an option

  • Save mxxntype/a1bbebbb7d7efcc04c23ba0db1b73a61 to your computer and use it in GitHub Desktop.

Select an option

Save mxxntype/a1bbebbb7d7efcc04c23ba0db1b73a61 to your computer and use it in GitHub Desktop.
A snippet of using eyre::Report
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(())
}
@mxxntype
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment