Skip to content

Commit

Permalink
Leverage default for log level argument, now it is optional so it can…
Browse files Browse the repository at this point in the history
… be properly override.
  • Loading branch information
danielsanchezq committed Aug 3, 2020
1 parent a743315 commit a6759d3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
24 changes: 17 additions & 7 deletions vit-servicing-station-lib/src/server/settings/config.rs
Expand Up @@ -107,8 +107,8 @@ pub struct Log {
pub log_output_path: Option<String>,

/// Application logging level
#[structopt(long, default_value = "disabled")]
pub log_level: LogLevel,
#[structopt(long)]
pub log_level: Option<LogLevel>,

/// Mute stdout log
#[serde(default)]
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
}
}
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion vit-servicing-station-server/src/main.rs
Expand Up @@ -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,
Expand Down

0 comments on commit a6759d3

Please sign in to comment.