From f8871bb2df967641d4e60251845d2b17e7de819c Mon Sep 17 00:00:00 2001 From: "James O. D. Hunt" Date: Fri, 1 Dec 2023 12:21:20 +0000 Subject: [PATCH] libs:logging: Fix logger PR #8311 inadvertently broke the logging since no log messages below the `Info` level are logged now, regardless of the requested log level. Resolve the issue by storing the requested log level in the `RuntimeComponentLevelFilter` and using that level in the `log()` function, rather than hard-coding `Info` as the default where no entry is found in the `FILTER_RULE` hashmap. Fixes: #8546. Signed-off-by: James O. D. Hunt --- src/libs/logging/src/lib.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/libs/logging/src/lib.rs b/src/libs/logging/src/lib.rs index 9e6c42544cd6..1d5a8242d34b 100644 --- a/src/libs/logging/src/lib.rs +++ b/src/libs/logging/src/lib.rs @@ -68,7 +68,7 @@ pub fn create_term_logger(level: slog::Level) -> (slog::Logger, slog_async::Asyn }); // Allow runtime filtering of records by log level - let filter_drain = RuntimeComponentLevelFilter::new(unique_drain).fuse(); + let filter_drain = RuntimeComponentLevelFilter::new(unique_drain, level).fuse(); // Ensure the logger is thread-safe let (async_drain, guard) = slog_async::Async::new(filter_drain) @@ -112,7 +112,7 @@ where }); // Allow runtime filtering of records by log level - let filter_drain = RuntimeComponentLevelFilter::new(unique_drain).fuse(); + let filter_drain = RuntimeComponentLevelFilter::new(unique_drain, level).fuse(); // Ensure the logger is thread-safe let (async_drain, guard) = slog_async::Async::new(filter_drain) @@ -283,11 +283,12 @@ where // specified in the struct according to the component it belongs to. struct RuntimeComponentLevelFilter { drain: D, + log_level: slog::Level, } impl RuntimeComponentLevelFilter { - fn new(drain: D) -> Self { - RuntimeComponentLevelFilter { drain } + fn new(drain: D, log_level: slog::Level) -> Self { + RuntimeComponentLevelFilter { drain, log_level } } } @@ -329,7 +330,7 @@ where } let according_level = component_level_config .get(&component.unwrap_or(DEFAULT_SUBSYSTEM.to_string())) - .unwrap_or(&slog::Level::Info); + .unwrap_or(&self.log_level); if record.level().is_at_least(*according_level) { self.drain.log(record, values)?; }