diff --git a/influxdb_iox/src/commands/tracing.rs b/influxdb_iox/src/commands/tracing.rs index 22e0da331e..5303da3227 100644 --- a/influxdb_iox/src/commands/tracing.rs +++ b/influxdb_iox/src/commands/tracing.rs @@ -1,9 +1,8 @@ //! Log and trace initialization and setup -use observability_deps::tracing::subscriber; use std::cmp::max; pub use trogging::config::*; -pub use trogging::TroggingGuard; +pub use trogging::{self, TroggingGuard}; use trogging::{ cli::LoggingConfigBuilderExt, tracing_subscriber::{prelude::*, Registry}, @@ -45,7 +44,5 @@ pub fn init_logs_and_tracing( }; let subscriber = Registry::default().with(layers); - subscriber::set_global_default(subscriber)?; - - Ok(TroggingGuard) + trogging::install_global(subscriber) } diff --git a/trogging/src/cli.rs b/trogging/src/cli.rs index 37f026ae4a..ae088a0928 100644 --- a/trogging/src/cli.rs +++ b/trogging/src/cli.rs @@ -1,5 +1,5 @@ ///! Common CLI flags for logging and tracing -use crate::{config::*, Builder, Result, TroggingGuard}; +use crate::{config::*, Builder}; use tracing_subscriber::fmt::{writer::BoxMakeWriter, MakeWriter}; /// CLI config for the logging related subset of options. @@ -120,10 +120,6 @@ impl LoggingConfig { .with_log_destination(self.log_destination) .with_log_format(self.log_format) } - - pub fn install_global_subscriber(&self) -> Result { - self.to_builder().install_global() - } } /// Extends the trogging [`crate::Builder`] API. diff --git a/trogging/src/lib.rs b/trogging/src/lib.rs index 8758d858d6..8a3f4cab35 100644 --- a/trogging/src/lib.rs +++ b/trogging/src/lib.rs @@ -246,12 +246,25 @@ where pub fn install_global(self) -> Result { let layer = self.build()?; let subscriber = tracing_subscriber::Registry::default().with(layer); - tracing::subscriber::set_global_default(subscriber)?; - tracing_log::LogTracer::init()?; - Ok(TroggingGuard) + install_global(subscriber) } } +/// Install a global tracing/logging subscriber. +/// +/// Call this function when installing a subscriber instead of calling +/// `tracing::subscriber::set_global_default` directly. +/// +/// This function also sets up the `log::Log` -> `tracing` bridge. +pub fn install_global(subscriber: S) -> Result +where + S: Subscriber + Send + Sync + 'static, +{ + tracing::subscriber::set_global_default(subscriber)?; + tracing_log::LogTracer::init()?; + Ok(TroggingGuard) +} + /// A RAII guard. On Drop, ensures all events are flushed /// /// Note: This is currently unnecessary but has been kept in case we choose to