Skip to content

Commit

Permalink
fix: Support all logger level case variants
Browse files Browse the repository at this point in the history
#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 332f218

Signed-off-by: Jonathan Woollett-Light <jcawl@amazon.co.uk>
Signed-off-by: Sudan Landge <sudanl@amazon.com>
  • Loading branch information
Jonathan Woollett-Light authored and wearyzen committed Nov 24, 2023
1 parent da92bf6 commit b6c543f
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/vmm/src/logger/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,13 @@ pub struct LevelFilterFromStrError(String);
impl FromStr for LevelFilter {
type Err = LevelFilterFromStrError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
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))),
}
}
Expand Down Expand Up @@ -301,13 +301,21 @@ 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));
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("warning"), Ok(LevelFilter::Warn));
assert_eq!(LevelFilter::from_str("Warning"), Ok(LevelFilter::Warn));
assert_eq!(LevelFilter::from_str("WARNING"), Ok(LevelFilter::Warn));
}
Expand Down

0 comments on commit b6c543f

Please sign in to comment.