From 07cac6ddcee92a5c0368f59dd9b432f91b0078a5 Mon Sep 17 00:00:00 2001 From: Alex Koshelev Date: Thu, 12 Dec 2024 14:50:02 -0800 Subject: [PATCH] Keep both stderr and file writers --- ipa-core/src/cli/verbosity.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/ipa-core/src/cli/verbosity.rs b/ipa-core/src/cli/verbosity.rs index b1b201ad4..f52c02ccd 100644 --- a/ipa-core/src/cli/verbosity.rs +++ b/ipa-core/src/cli/verbosity.rs @@ -45,7 +45,14 @@ impl Verbosity { let filter_layer = self.log_filter(); info!("Logging setup at level {}", filter_layer); - let registry = tracing_subscriber::registry().with(filter_layer); + let stderr_writer = fmt::layer() + .with_span_events(FmtSpan::NEW | FmtSpan::CLOSE) + .with_ansi(std::io::stderr().is_terminal()) + .with_writer(stderr); + + let registry = tracing_subscriber::registry() + .with(filter_layer) + .with(stderr_writer); if let Some(path) = &self.log_file { let log_file = OpenOptions::new() @@ -53,21 +60,17 @@ impl Verbosity { .create(true) .open(path) .unwrap_or_else(|e| panic!("failed to open log file {path:?}: {e}")); - let fmt_layer = fmt::layer() + let file_writer = fmt::layer() .with_span_events(FmtSpan::NEW | FmtSpan::CLOSE) .with_ansi(false) .with_writer(log_file); // that's the only stderr message that should appear to give a hint where // the logs are written to - eprintln!("Logs will be written to {path:?}"); - registry.with(fmt_layer).init(); + tracing::info!("Logs will be written to {path:?}"); + registry.with(file_writer).init(); } else { - let fmt_layer = fmt::layer() - .with_span_events(FmtSpan::NEW | FmtSpan::CLOSE) - .with_ansi(std::io::stderr().is_terminal()) - .with_writer(stderr); - registry.with(fmt_layer).init(); + registry.init(); } let metrics_handle = install_collector().expect("Can install metrics");