geist_supervisor 0.1.28

Generic OTA supervisor for field devices
Documentation
use std::io;
use tracing_subscriber::{fmt, fmt::format::FmtSpan, EnvFilter};

pub fn init_logging() {
    // Initialize tracing subscriber with formatting and filtering
    let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info"));

    // When debug assertions are enabled or the verbose_logging feature is enabled,
    // include more detailed information
    #[cfg(any(debug_assertions, feature = "verbose_logging"))]
    {
        if fmt::Subscriber::builder()
            .with_env_filter(filter)
            .with_span_events(FmtSpan::CLOSE)
            .with_target(true)
            .with_thread_ids(true)
            .with_thread_names(true)
            .with_file(true)
            .with_line_number(true)
            .with_writer(io::stderr) // Write to stderr instead of stdout
            .try_init()
            .is_err()
        {
            // Subscriber already set, nothing to do
        }
    }

    // In release mode without the verbose_logging feature, use an extremely minimal format
    #[cfg(not(any(debug_assertions, feature = "verbose_logging")))]
    {
        if fmt::Subscriber::builder()
            .with_env_filter(filter)
            .with_span_events(FmtSpan::NONE)
            .with_target(false)
            .with_thread_ids(false)
            .with_thread_names(false)
            .with_file(false)
            .with_line_number(false)
            .without_time() // No timestamp for minimal output
            .with_ansi(false) // Disable colors for cleaner output
            .compact() // Use compact format
            .with_writer(io::stderr) // Write to stderr instead of stdout
            .try_init()
            .is_err()
        {
            // Subscriber already set, nothing to do
        }
    }
}