fix: Make us log logs from the log crate again (#5680)

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
pull/24376/head
Marko Mikulicic 2022-09-20 01:04:28 +02:00 committed by GitHub
parent 14a6b437d8
commit 46ab254dfb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 13 deletions

View File

@ -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)
}

View File

@ -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<TroggingGuard> {
self.to_builder().install_global()
}
}
/// Extends the trogging [`crate::Builder`] API.

View File

@ -246,12 +246,25 @@ where
pub fn install_global(self) -> Result<TroggingGuard> {
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<S>(subscriber: S) -> Result<TroggingGuard>
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