2026-11-23 01:15:26 +01:00
|
|
|
//! One tracing setup for every binary.
|
|
|
|
|
//!
|
|
|
|
|
//! Filter with `VICTORY_LOG` (falls back to `RUST_LOG`), e.g.
|
2026-11-23 23:10:01 +01:00
|
|
|
//! `VICTORY_LOG=victory_loader=trace,info`. Debug and trace output exist
|
|
|
|
|
//! only in builds with the `diagnostics` feature; a plain release build
|
|
|
|
|
//! logs info and above whatever the filter asks for.
|
2026-11-23 01:15:26 +01:00
|
|
|
|
|
|
|
|
use tracing_subscriber::EnvFilter;
|
2026-11-23 23:10:01 +01:00
|
|
|
use tracing_subscriber::filter::LevelFilter;
|
|
|
|
|
use tracing_subscriber::layer::SubscriberExt;
|
|
|
|
|
use tracing_subscriber::util::SubscriberInitExt;
|
|
|
|
|
|
|
|
|
|
/// The most verbose level this build can log.
|
|
|
|
|
const CAP: LevelFilter = if cfg!(feature = "diagnostics") {
|
|
|
|
|
LevelFilter::TRACE
|
|
|
|
|
} else {
|
|
|
|
|
LevelFilter::INFO
|
|
|
|
|
};
|
2026-11-23 01:15:26 +01:00
|
|
|
|
|
|
|
|
pub fn init(default_level: &str) {
|
|
|
|
|
let filter = std::env::var("VICTORY_LOG")
|
|
|
|
|
.or_else(|_| std::env::var("RUST_LOG"))
|
|
|
|
|
.ok()
|
|
|
|
|
.and_then(|v| EnvFilter::try_new(v).ok())
|
|
|
|
|
.unwrap_or_else(|| EnvFilter::new(default_level));
|
2026-11-23 23:10:01 +01:00
|
|
|
let _ = tracing_subscriber::registry()
|
|
|
|
|
.with(CAP)
|
|
|
|
|
.with(filter)
|
|
|
|
|
.with(
|
|
|
|
|
tracing_subscriber::fmt::layer()
|
|
|
|
|
.with_target(true)
|
|
|
|
|
.with_writer(std::io::stderr),
|
|
|
|
|
)
|
2026-11-23 01:15:26 +01:00
|
|
|
.try_init();
|
|
|
|
|
}
|