Skip to content

Commit

Permalink
Log: Add option to set LevelFilter at compile time (#53)
Browse files Browse the repository at this point in the history
If the Environment variable HERMIT_LOG_LEVEL_FILTER is set at compile time to a string matching the Name of a Levelfilter enum value, then that value is used for the Levelfilter.
If the Environment variable is not set, or the name doesn't match, then LevelFilter::Info is used by default, which is the same as it was before.
  • Loading branch information
jschwe authored May 17, 2020
1 parent e5d8cc9 commit 5f8697b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,18 @@ impl log::Log for KernelLogger {

pub fn init() {
set_logger(&KernelLogger).expect("Can't initialize logger");
set_max_level(LevelFilter::Info);
// 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,
};
set_max_level(max_level);
}

macro_rules! infoheader {
Expand Down

0 comments on commit 5f8697b

Please sign in to comment.