mecha10-runtime 0.8.0

Runtime supervisor for Mecha10 nodes - launching, monitoring, and lifecycle management
Documentation
//! Logging initialization and configuration

use crate::config::LogFormat;
use tracing_subscriber::{fmt, prelude::*, EnvFilter};

/// Initialize logging with the specified format and level
///
/// Note: This can only be called once per process. Subsequent calls will be ignored.
pub fn init_logging(level: &str, format: LogFormat) {
    let env_filter = std::env::var("LOG_LEVEL")
        .ok()
        .map(EnvFilter::new)
        .or_else(|| EnvFilter::try_from_default_env().ok())
        .unwrap_or_else(|| EnvFilter::new(format!("{level},rtc_ice=error,rtc::peer_connection::handler=error")));

    let result = match format {
        LogFormat::Pretty => tracing_subscriber::registry()
            .with(env_filter)
            .with(fmt::layer().pretty())
            .try_init(),
        LogFormat::Json => tracing_subscriber::registry()
            .with(env_filter)
            .with(fmt::layer().json().flatten_event(true))
            .try_init(),
        LogFormat::Compact => tracing_subscriber::registry()
            .with(env_filter)
            .with(fmt::layer().compact())
            .try_init(),
    };

    let _ = result;
}