miden_node_utils/
logging.rs

1use anyhow::Result;
2use tracing::subscriber::{self, Subscriber};
3use tracing_subscriber::EnvFilter;
4
5pub fn setup_logging() -> Result<()> {
6    subscriber::set_global_default(subscriber())?;
7
8    Ok(())
9}
10
11#[cfg(not(feature = "tracing-forest"))]
12pub fn subscriber() -> impl Subscriber + core::fmt::Debug {
13    use tracing_subscriber::fmt::format::FmtSpan;
14
15    tracing_subscriber::fmt()
16        .pretty()
17        .compact()
18        .with_level(true)
19        .with_file(true)
20        .with_line_number(true)
21        .with_target(true)
22        .with_env_filter(EnvFilter::try_from_default_env().unwrap_or_else(|_| {
23            // axum logs rejections from built-in extracts on the trace level, so we enable this
24            // manually.
25            "info,axum::rejection=trace".into()
26        }))
27        .with_span_events(FmtSpan::NEW | FmtSpan::CLOSE)
28        .finish()
29}
30
31#[cfg(feature = "tracing-forest")]
32pub fn subscriber() -> impl Subscriber + core::fmt::Debug {
33    pub use tracing_forest::ForestLayer;
34    pub use tracing_subscriber::{layer::SubscriberExt, Registry};
35
36    Registry::default().with(ForestLayer::default()).with(
37        EnvFilter::try_from_default_env().unwrap_or_else(|_| {
38            // axum logs rejections from built-in extracts on the trace level, so we enable this
39            // manually.
40            "info,axum::rejection=trace".into()
41        }),
42    )
43}