//! Tracing initialization. //! //! Call `init_tracing()` during application startup to set up the //! tracing-subscriber fmt layer (writes human-readable spans to stderr). use tracing_subscriber::{fmt, EnvFilter}; use tracing_subscriber::layer::SubscriberExt; /// Initialize tracing with a fmt layer. /// /// The `EnvFilter` reads the `RUST_LOG` environment variable to /// set the log level (e.g. `RUST_LOG=info`). pub fn init_tracing() { let env_filter = EnvFilter::try_from_default_env() .unwrap_or_else(|_| EnvFilter::new("info")); let fmt_layer = fmt::layer() .with_target(true) .with_thread_ids(false) .with_file(true) .with_line_number(true) .compact(); let registry = tracing_subscriber::registry() .with(env_filter) .with(fmt_layer); tracing::subscriber::set_global_default(registry) .expect("failed to set global tracing subscriber"); }