| 1234567891011121314151617181920212223242526272829303132333435 |
- //! One tracing setup for every binary.
- //!
- //! Filter with `VICTORY_LOG` (falls back to `RUST_LOG`), e.g.
- //! `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.
- use tracing_subscriber::EnvFilter;
- 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
- };
- 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));
- let _ = tracing_subscriber::registry()
- .with(CAP)
- .with(filter)
- .with(
- tracing_subscriber::fmt::layer()
- .with_target(true)
- .with_writer(std::io::stderr),
- )
- .try_init();
- }
|