From 5f8697b0f55dcd7cf51d4ae25d19cb5027ecbc68 Mon Sep 17 00:00:00 2001 From: jschwe <55576758+jschwe@users.noreply.github.com> Date: Sun, 17 May 2020 11:12:26 +0200 Subject: [PATCH] Log: Add option to set LevelFilter at compile time (#53) 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. --- src/logging.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/logging.rs b/src/logging.rs index 179d101ab8..5196698b49 100644 --- a/src/logging.rs +++ b/src/logging.rs @@ -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 {