Skip to content

Commit

Permalink
libs:logging: Fix logger
Browse files Browse the repository at this point in the history
PR kata-containers#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: kata-containers#8546.

Signed-off-by: James O. D. Hunt <[email protected]>
  • Loading branch information
jodh-intel authored and danmihai1 committed Nov 13, 2024
1 parent 52039cb commit f8871bb
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/libs/logging/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -283,11 +283,12 @@ where
// specified in the struct according to the component it belongs to.
struct RuntimeComponentLevelFilter<D> {
drain: D,
log_level: slog::Level,
}

impl<D> RuntimeComponentLevelFilter<D> {
fn new(drain: D) -> Self {
RuntimeComponentLevelFilter { drain }
fn new(drain: D, log_level: slog::Level) -> Self {
RuntimeComponentLevelFilter { drain, log_level }
}
}

Expand Down Expand Up @@ -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)?;
}
Expand Down

0 comments on commit f8871bb

Please sign in to comment.