From 33d5a514a26aaf7a2db7a67b5bc2c8a7aa480ec2 Mon Sep 17 00:00:00 2001 From: Yorgos Saslis Date: Tue, 19 May 2026 14:22:26 +0000 Subject: [PATCH] feat(logger.rs): honor RUST_LOG for per-module log filtering Use the tracing-subscriber `EnvFilter::builder()` + `from_env_lossy()` pattern so `RUST_LOG`, when set, takes precedence over the `--log-level` flag. This lets operators silence noisy dependencies (e.g. radicle-cob's "Loading object of type ..." debug stream emitted with `target: "cob"`) while keeping the broker itself at `debug` level. Example: `RUST_LOG="debug,cob=info" cib ...` `from_env_lossy()` also reports invalid directives to stderr ("ignoring '': ") instead of swallowing them, so this allows operators to quickly realise if they've set the wrong log level. This also works with `log` crate records (most heartwood crates), as they are bridged into tracing via tracing-subscriber's default-enabled `tracing-log` feature, so they respect the same directives. Also fixes typos in the `--log-level` doc-comment. Signed-off-by: Yorgos Saslis --- src/bin/cib.rs | 8 ++++++-- src/logger.rs | 5 +++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/bin/cib.rs b/src/bin/cib.rs index b13ac171..01efd0f0 100644 --- a/src/bin/cib.rs +++ b/src/bin/cib.rs @@ -61,8 +61,12 @@ struct Args { #[clap(long)] config: PathBuf, - /// Se the global log level. Log messages that on at least this - /// level get written to the standard error output. + /// Set the global log level. Log messages at this level or + /// higher get written to the standard error output. + /// + /// Overridden by the `RUST_LOG` environment variable when set, + /// which accepts per-module directives like `debug,cob=info` + /// for finer control over noisy dependencies. #[clap(long, value_enum)] log_level: Option, diff --git a/src/logger.rs b/src/logger.rs index 08700ed4..db802eeb 100644 --- a/src/logger.rs +++ b/src/logger.rs @@ -271,7 +271,6 @@ impl From for tracing::Level { } } -#[allow(clippy::unwrap_used)] pub fn open(level: LogLevel) { #[cfg(test)] let writer = fmt::TestWriter::new(); @@ -281,7 +280,9 @@ pub fn open(level: LogLevel) { let fmt_layer = fmt::layer().with_target(false).with_writer(writer).json(); - let filter_layer = EnvFilter::try_new(level.to_string()).unwrap(); + let filter_layer = EnvFilter::builder() + .with_default_directive(Level::from(level).into()) + .from_env_lossy(); tracing_subscriber::registry() .with(filter_layer)