/// Start log or trace emitter. Panics on error.
Start log or trace emitter. Panics on error.
Start log or trace emitter . Panics on error .
pub fn init_logs_and_tracing(
    log_verbose_count: u8,
    config: &crate::commands::run::Config,
) -> Result<TracingGuard, SetGlobalDefaultError> {
    // Handle the case if -v/-vv is specified both before and after the server
    // command
    let log_verbose_count = if log_verbose_count > config.log_verbose_count {
        log_verbose_count
    } else {
        config.log_verbose_count
    };
    let (traces_layer_filter, traces_layer_otel) = match construct_opentelemetry_tracer(config) {
        None => (None, None),
        Some(tracer) => {
            let traces_layer_otel = Some(tracing_opentelemetry::OpenTelemetryLayer::new(tracer));
            match &config.traces_filter {
                None => (None, traces_layer_otel),
                Some(traces_filter) => (
                    Some(EnvFilter::try_new(traces_filter).unwrap()),
                    traces_layer_otel,
                ),
            }
        }
    };
    let (
        log_layer_filter,
        log_layer_format_full,
        log_layer_format_pretty,
        log_layer_format_json,
        log_layer_format_logfmt,
    ) = {
        match traces_layer_otel {
            Some(_) => (None, None, None, None, None),
            None => {
                // Note: Use LineWriter to ensure each log line is
                // written as a unit and avoid interleaving
                // see https://github.com/influxdata/influxdb_iox/issues/1615
                let log_writer = match config.log_destination {
                    LogDestination::Stdout => fmt::writer::BoxMakeWriter::new(|| {
                        std::io::LineWriter::new(std::io::stdout())
                    }),
                    LogDestination::Stderr => fmt::writer::BoxMakeWriter::new(|| {
                        std::io::LineWriter::new(std::io::stderr())
                    }),
                };
                let (log_format_full, log_format_pretty, log_format_json, log_format_logfmt) =
                    match config.log_format {
                        LogFormat::Full => {
                            (Some(fmt::layer().with_writer(log_writer)), None, None, None)
                        }
                        LogFormat::Pretty => (
                            None,
                            Some(fmt::layer().pretty().with_writer(log_writer)),
                            None,
                            None,
                        ),
                        LogFormat::Json => (
                            None,
                            None,
                            Some(fmt::layer().json().with_writer(log_writer)),
                            None,
                        ),
                        LogFormat::Logfmt => {
                            (None, None, None, Some(logfmt::LogFmtLayer::new(log_writer)))
                        }
                    };
                let log_layer_filter = match log_verbose_count {
                    0 => EnvFilter::try_new(&config.log_filter).unwrap(),
                    1 => EnvFilter::try_new("info").unwrap(),
                    2 => EnvFilter::try_new("debug,hyper::proto::h1=info,h2=info").unwrap(),
                    _ => EnvFilter::try_new("trace,hyper::proto::h1=info,h2=info").unwrap(),
                };
                (
                    Some(log_layer_filter),
                    log_format_full,
                    log_format_pretty,
                    log_format_json,
                    log_format_logfmt,
                )
            }
        }
    };
    let subscriber = tracing_subscriber::Registry::default()
        .with(log_layer_format_logfmt)
        .with(log_layer_format_json)
        .with(log_layer_format_pretty)
        .with(log_layer_format_full)
        .with(log_layer_filter)
        .with(traces_layer_otel)
        .with(traces_layer_filter);
    tracing::subscriber::set_global_default(subscriber)?;
    Ok(TracingGuard)
}
pub fn init_logs_and_tracing ( log_verbose_count : u8 , config : & crate :: commands :: run :: Config , ) -> Result < TracingGuard , SetGlobalDefaultError > { // Handle the case if -v/-vv is specified both before and after the server // command let log_verbose_count = if log_verbose_count > config . log_verbose_count { log_verbose_count } else { config . log_verbose_count } ; let ( traces_layer_filter , traces_layer_otel ) = match construct_opentelemetry_tracer ( config ) { None => ( None , None ) , Some ( tracer ) => { let traces_layer_otel = Some ( tracing_opentelemetry :: OpenTelemetryLayer :: new ( tracer ) ) ; match & config . traces_filter { None => ( None , traces_layer_otel ) , Some ( traces_filter ) => ( Some ( EnvFilter :: try_new ( traces_filter ) . unwrap ( ) ) , traces_layer_otel , ) , } } } ; let ( log_layer_filter , log_layer_format_full , log_layer_format_pretty , log_layer_format_json , log_layer_format_logfmt , ) = { match traces_layer_otel { Some ( _ ) => ( None , None , None , None , None ) , None => { // Note: Use LineWriter to ensure each log line is // written as a unit and avoid interleaving // see https://github.com/influxdata/influxdb_iox/issues/1615 let log_writer = match config . log_destination { LogDestination :: Stdout => fmt :: writer :: BoxMakeWriter :: new ( | | { std :: io :: LineWriter :: new ( std :: io :: stdout ( ) ) } ) , LogDestination :: Stderr => fmt :: writer :: BoxMakeWriter :: new ( | | { std :: io :: LineWriter :: new ( std :: io :: stderr ( ) ) } ) , } ; let ( log_format_full , log_format_pretty , log_format_json , log_format_logfmt ) = match config . log_format { LogFormat :: Full => { ( Some ( fmt :: layer ( ) . with_writer ( log_writer ) ) , None , None , None ) } LogFormat :: Pretty => ( None , Some ( fmt :: layer ( ) . pretty ( ) . with_writer ( log_writer ) ) , None , None , ) , LogFormat :: Json => ( None , None , Some ( fmt :: layer ( ) . json ( ) . with_writer ( log_writer ) ) , None , ) , LogFormat :: Logfmt => { ( None , None , None , Some ( logfmt :: LogFmtLayer :: new ( log_writer ) ) ) } } ; let log_layer_filter = match log_verbose_count { 0 => EnvFilter :: try_new ( & config . log_filter ) . unwrap ( ) , 1 => EnvFilter :: try_new ( " " ) . unwrap ( ) , 2 => EnvFilter :: try_new ( " " ) . unwrap ( ) , _ => EnvFilter :: try_new ( " " ) . unwrap ( ) , } ; ( Some ( log_layer_filter ) , log_format_full , log_format_pretty , log_format_json , log_format_logfmt , ) } } } ; let subscriber = tracing_subscriber :: Registry :: default ( ) . with ( log_layer_format_logfmt ) . with ( log_layer_format_json ) . with ( log_layer_format_pretty ) . with ( log_layer_format_full ) . with ( log_layer_filter ) . with ( traces_layer_otel ) . with ( traces_layer_filter ) ; tracing :: subscriber :: set_global_default ( subscriber ) ? ; Ok ( TracingGuard ) }
Start log or trace emitter.
Start log or trace emitter .
log_verbose_count
u8
config
&crate::commands::run::Config