diff --git a/vit-servicing-station-lib/src/server/settings/config.rs b/vit-servicing-station-lib/src/server/settings/config.rs index 34bf2958..da9820e6 100644 --- a/vit-servicing-station-lib/src/server/settings/config.rs +++ b/vit-servicing-station-lib/src/server/settings/config.rs @@ -107,8 +107,8 @@ pub struct Log { pub log_output_path: Option, /// Application logging level - #[structopt(long, default_value = "disabled")] - pub log_level: LogLevel, + #[structopt(long)] + pub log_level: Option, /// Mute stdout log #[serde(default)] @@ -160,13 +160,17 @@ impl ServiceSettings { return_settings.block0_path = other_settings.block0_path.clone(); } - return_settings.log.log_level = other_settings.log.log_level; + if other_settings.log.log_level.is_some() { + return_settings.log.log_level = other_settings.log.log_level; + } if other_settings.log.log_output_path.is_some() { return_settings.log.log_output_path = other_settings.log.log_output_path.clone(); } - return_settings.log.mute_terminal_log = other_settings.log.mute_terminal_log; + if other_settings.log.mute_terminal_log { + return_settings.log.mute_terminal_log = other_settings.log.mute_terminal_log; + } return_settings } @@ -293,11 +297,17 @@ impl FromStr for LogLevel { } } +impl Default for LogLevel { + fn default() -> Self { + LogLevel::Disabled + } +} + impl Default for Log { fn default() -> Self { Self { log_output_path: None, - log_level: LogLevel::Disabled, + log_level: None, mute_terminal_log: false, } } @@ -373,7 +383,7 @@ mod test { ); assert_eq!(config.block0_path, "./test/bin.test"); assert_eq!(config.log.log_output_path.unwrap(), "./server.log"); - assert_eq!(config.log.log_level, LogLevel::Error); + assert_eq!(config.log.log_level, Some(LogLevel::Error)); let tls_config = config.tls; let cors_config = config.cors; assert_eq!(tls_config.cert_file.unwrap(), "./foo/bar.pem"); @@ -434,7 +444,7 @@ mod test { CorsOrigin("https://foo.test".to_string()) ); assert_eq!(settings.log.log_output_path.unwrap(), "./log.log"); - assert_eq!(settings.log.log_level, LogLevel::Error); + assert_eq!(settings.log.log_level, Some(LogLevel::Error)); } #[test] diff --git a/vit-servicing-station-server/src/main.rs b/vit-servicing-station-server/src/main.rs index 91c013e2..e983e9d0 100644 --- a/vit-servicing-station-server/src/main.rs +++ b/vit-servicing-station-server/src/main.rs @@ -34,7 +34,7 @@ async fn main() { // setup logging config_log( - settings.log.log_level.into(), + settings.log.log_level.unwrap_or_default().into(), settings.log.log_output_path.clone(), settings.log.mute_terminal_log, None,