Skip to content

Commit

Permalink
Merge pull request #1494 from hermit-os/insensitive-log-level-filter
Browse files Browse the repository at this point in the history
feat(log): make `HERMIT_LOG_LEVEL_FILTER` case-insensitive
  • Loading branch information
mkroening authored Dec 2, 2024
2 parents 064998e + c3cef68 commit 934bc5c
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,27 @@ pub unsafe fn init() {
log::set_logger(&KernelLogger).expect("Can't initialize logger");
// Determines LevelFilter at compile time
let log_level: Option<&'static str> = option_env!("HERMIT_LOG_LEVEL_FILTER");
let max_level: LevelFilter = match log_level {
Some("Error") => LevelFilter::Error,
Some("Debug") => LevelFilter::Debug,
Some("Off") => LevelFilter::Off,
Some("Trace") => LevelFilter::Trace,
Some("Warn") => LevelFilter::Warn,
Some("Info") => LevelFilter::Info,
_ => LevelFilter::Info,
};
let mut max_level = LevelFilter::Info;

if let Some(log_level) = log_level {
max_level = if log_level.eq_ignore_ascii_case("off") {
LevelFilter::Off
} else if log_level.eq_ignore_ascii_case("error") {
LevelFilter::Error
} else if log_level.eq_ignore_ascii_case("warn") {
LevelFilter::Warn
} else if log_level.eq_ignore_ascii_case("info") {
LevelFilter::Info
} else if log_level.eq_ignore_ascii_case("debug") {
LevelFilter::Debug
} else if log_level.eq_ignore_ascii_case("trace") {
LevelFilter::Trace
} else {
error!("Could not parse HERMIT_LOG_LEVEL_FILTER, falling back to `info`.");
LevelFilter::Info
};
}

log::set_max_level(max_level);
}

Expand Down

0 comments on commit 934bc5c

Please sign in to comment.