diff --git a/zebrad/src/application.rs b/zebrad/src/application.rs index df41a2b3..24956341 100644 --- a/zebrad/src/application.rs +++ b/zebrad/src/application.rs @@ -139,16 +139,24 @@ impl Application for ZebradApp { .map(ZebradCmd::is_server) .unwrap_or(false); - // Launch network endpoints for long-running commands + // Launch network endpoints only for long-running commands. if is_server { - let filter = cfg_ref.tracing.filter.as_deref().unwrap_or(default_filter); - let flame_root = cfg_ref.tracing.flamegraph.as_deref(); - components.push(Box::new(Tracing::new(filter, flame_root)?)); + // Override the default tracing filter based on the command-line verbosity. + let mut tracing_config = cfg_ref.tracing.clone(); + tracing_config.filter = tracing_config + .filter + .or_else(|| Some(default_filter.to_owned())); + + components.push(Box::new(Tracing::new(tracing_config)?)); components.push(Box::new(TokioComponent::new()?)); components.push(Box::new(TracingEndpoint::new(cfg_ref)?)); components.push(Box::new(MetricsEndpoint::new(cfg_ref)?)); } else { - components.push(Box::new(Tracing::new(default_filter, None)?)); + // Don't apply the configured filter for short-lived commands. + let mut tracing_config = cfg_ref.tracing.clone(); + tracing_config.filter = Some(default_filter.to_owned()); + tracing_config.flamegraph = None; + components.push(Box::new(Tracing::new(tracing_config)?)); } self.state.components.register(components) diff --git a/zebrad/src/components/tracing/component.rs b/zebrad/src/components/tracing/component.rs index 48f510cc..3ee54aa7 100644 --- a/zebrad/src/components/tracing/component.rs +++ b/zebrad/src/components/tracing/component.rs @@ -1,12 +1,11 @@ -use std::path::Path; - +use abscissa_core::{Component, FrameworkError, FrameworkErrorKind, Shutdown}; use tracing_error::ErrorLayer; use tracing_subscriber::{ fmt::Formatter, layer::SubscriberExt, reload::Handle, util::SubscriberInitExt, EnvFilter, FmtSubscriber, }; -use abscissa_core::{Component, FrameworkError, FrameworkErrorKind, Shutdown}; +use crate::config::TracingSection; use super::flame; @@ -18,7 +17,10 @@ pub struct Tracing { impl Tracing { /// Try to create a new [`Tracing`] component with the given `filter`. - pub fn new(filter: &str, flame_root: Option<&Path>) -> Result { + pub fn new(config: TracingSection) -> Result { + let filter = config.filter.unwrap_or_else(|| "".to_string()); + let flame_root = &config.flamegraph; + // Construct a tracing subscriber with the supplied filter and enable reloading. let builder = FmtSubscriber::builder() .with_ansi(true)