Skip to content

Commit

Permalink
Added mute stdout log argument
Browse files Browse the repository at this point in the history
Default log to be disabled
  • Loading branch information
danielsanchezq committed Aug 3, 2020
1 parent 9dc2026 commit 18c1793
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
16 changes: 10 additions & 6 deletions logging-lib/src/config.rs
Expand Up @@ -5,15 +5,19 @@ use std::fs::File;
pub fn config_log(
level: LevelFilter,
file_log_path: Option<String>,
mute_terminal: bool,
config: Option<Config>,
) -> std::io::Result<()> {
let terminal_logger = TermLogger::new(
level,
config.clone().unwrap_or_default(),
TerminalMode::Mixed,
);
let mut log_vec: Vec<Box<dyn SharedLogger>> = Vec::new();

let mut log_vec: Vec<Box<dyn SharedLogger>> = vec![terminal_logger];
if !mute_terminal {
let terminal_logger = TermLogger::new(
level,
config.clone().unwrap_or_default(),
TerminalMode::Mixed,
);
log_vec.push(terminal_logger);
}

if let Some(file_path) = file_log_path {
let file_logger =
Expand Down
20 changes: 18 additions & 2 deletions vit-servicing-station-lib/src/server/settings/config.rs
Expand Up @@ -107,8 +107,13 @@ pub struct Log {
pub log_output_path: Option<String>,

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

/// Mute stdout log
#[serde(default)]
#[structopt(long)]
pub mute_terminal_log: bool,
}

fn parse_allowed_origins(arg: &str) -> Result<AllowedOrigins, std::io::Error> {
Expand Down Expand Up @@ -155,6 +160,16 @@ impl ServiceSettings {
return_settings.block0_path = other_settings.block0_path.clone();
}

if other_settings.log.log_level != return_settings.log.log_level {
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;

return_settings
}
}
Expand Down Expand Up @@ -284,7 +299,8 @@ impl Default for Log {
fn default() -> Self {
Self {
log_output_path: None,
log_level: LogLevel::Info,
log_level: LogLevel::Disabled,
mute_terminal_log: false,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions vit-servicing-station-server/src/main.rs
Expand Up @@ -36,6 +36,7 @@ async fn main() {
config_log(
settings.log.log_level.into(),
settings.log.log_output_path.clone(),
settings.log.mute_terminal_log,
None,
)
.unwrap_or_else(|e| {
Expand Down
2 changes: 1 addition & 1 deletion vit-servicing-station-tests/jortestkit

0 comments on commit 18c1793

Please sign in to comment.