From b6c543fc59044b395ef1c068bea04c8aa3635f0e Mon Sep 17 00:00:00 2001 From: Jonathan Woollett-Light Date: Wed, 15 Nov 2023 10:40:52 +0000 Subject: [PATCH] fix: Support all logger level case variants https://github.com/firecracker-microvm/firecracker/pull/4047 updated parsing the logger level filter. It removed all case variants outside fully uppercase (e.g. `INFO`) and the 1st character being upper case (e.g. `Info`) this removed support for other previously supported variants e.g. `info`. This commit re-introduces this support such that all variants should again be supported. Fixes commit 332f2184ae29265fbae1648469e073fc7f987378 Signed-off-by: Jonathan Woollett-Light Signed-off-by: Sudan Landge --- src/vmm/src/logger/logging.rs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/vmm/src/logger/logging.rs b/src/vmm/src/logger/logging.rs index 7f45e4d2499..d111994363a 100644 --- a/src/vmm/src/logger/logging.rs +++ b/src/vmm/src/logger/logging.rs @@ -242,13 +242,13 @@ pub struct LevelFilterFromStrError(String); impl FromStr for LevelFilter { type Err = LevelFilterFromStrError; fn from_str(s: &str) -> Result { - match s { - "Off" | "OFF" => Ok(Self::Off), - "Trace" | "TRACE" => Ok(Self::Trace), - "Debug" | "DEBUG" => Ok(Self::Debug), - "Info" | "INFO" => Ok(Self::Info), - "Warn" | "WARN" | "Warning" | "WARNING" => Ok(Self::Warn), - "Error" | "ERROR" => Ok(Self::Error), + match s.to_ascii_lowercase().as_str() { + "off" => Ok(Self::Off), + "trace" => Ok(Self::Trace), + "debug" => Ok(Self::Debug), + "info" => Ok(Self::Info), + "warn" | "warning" => Ok(Self::Warn), + "error" => Ok(Self::Error), _ => Err(LevelFilterFromStrError(String::from(s))), } } @@ -301,6 +301,13 @@ mod tests { assert_eq!(LevelFilter::from_str("Warn"), Ok(LevelFilter::Warn)); assert_eq!(LevelFilter::from_str("Error"), Ok(LevelFilter::Error)); + assert_eq!(LevelFilter::from_str("off"), Ok(LevelFilter::Off)); + assert_eq!(LevelFilter::from_str("trace"), Ok(LevelFilter::Trace)); + assert_eq!(LevelFilter::from_str("debug"), Ok(LevelFilter::Debug)); + assert_eq!(LevelFilter::from_str("info"), Ok(LevelFilter::Info)); + assert_eq!(LevelFilter::from_str("warn"), Ok(LevelFilter::Warn)); + assert_eq!(LevelFilter::from_str("error"), Ok(LevelFilter::Error)); + assert_eq!(LevelFilter::from_str("OFF"), Ok(LevelFilter::Off)); assert_eq!(LevelFilter::from_str("TRACE"), Ok(LevelFilter::Trace)); assert_eq!(LevelFilter::from_str("DEBUG"), Ok(LevelFilter::Debug)); @@ -308,6 +315,7 @@ mod tests { assert_eq!(LevelFilter::from_str("WARN"), Ok(LevelFilter::Warn)); assert_eq!(LevelFilter::from_str("ERROR"), Ok(LevelFilter::Error)); + assert_eq!(LevelFilter::from_str("warning"), Ok(LevelFilter::Warn)); assert_eq!(LevelFilter::from_str("Warning"), Ok(LevelFilter::Warn)); assert_eq!(LevelFilter::from_str("WARNING"), Ok(LevelFilter::Warn)); }