|
|
|
@ -11,7 +11,7 @@ use std::io::Read; |
|
|
|
|
use std::path::{Path, PathBuf}; |
|
|
|
|
use std::str::FromStr; |
|
|
|
|
|
|
|
|
|
pub const LOG_LEVELS: [&str; 5] = ["error", "warn", "info", "debug", "trace"]; |
|
|
|
|
pub const LOG_LEVELS: [&str; 6] = ["off", "error", "warn", "info", "debug", "trace"]; |
|
|
|
|
|
|
|
|
|
/// Implement this for the main config struct
|
|
|
|
|
pub trait AppConfig: Sized + Serialize + DeserializeOwned + Debug + Default { |
|
|
|
@ -164,6 +164,13 @@ pub trait AppConfig: Sized + Serialize + DeserializeOwned + Debug + Default { |
|
|
|
|
|
|
|
|
|
builder.format_timestamp_millis(); |
|
|
|
|
|
|
|
|
|
let mut per_mod = vec![];
|
|
|
|
|
if let Some(mod_levels) = config.logging_mod_levels() { |
|
|
|
|
for (module, lvl) in mod_levels { |
|
|
|
|
per_mod.push((module, log::LevelFilter::from_str(lvl)?)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if let Some(suppress_mods) = config.logging_suppress_mods() { |
|
|
|
|
// set logging level for suppressed libs
|
|
|
|
|
let mut sup_lvl = log::LevelFilter::Info; |
|
|
|
@ -173,16 +180,20 @@ pub trait AppConfig: Sized + Serialize + DeserializeOwned + Debug + Default { |
|
|
|
|
sup_lvl = log::LevelFilter::Error; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for lib in suppress_mods { |
|
|
|
|
'sup: for lib in suppress_mods { |
|
|
|
|
for (module, _lvl) in per_mod.iter() { |
|
|
|
|
if lib.starts_with(module.as_str()) { |
|
|
|
|
// avoid suppressing if user set different level for a parent module
|
|
|
|
|
continue 'sup; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
builder.filter_module(lib, sup_lvl); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if let Some(mod_levels) = config.logging_mod_levels() { |
|
|
|
|
for (module, lvl) in mod_levels { |
|
|
|
|
let lvl = log::LevelFilter::from_str(lvl)?; |
|
|
|
|
builder.filter_module(module, lvl); |
|
|
|
|
} |
|
|
|
|
for (module, lvl) in per_mod.into_iter() { |
|
|
|
|
builder.filter_module(module, lvl); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
builder.init(); |
|
|
|
|