Fix: Overide logging with --debug
Formerly, the --debug flag was ignores. This change overrides the logging with the CLI specified logging if it was provided. If --debug was provided, the logging is set to debugging, if --verbose was provided info logging is used.
This commit is contained in:
parent
704c01b2c9
commit
817933c99f
1 changed files with 30 additions and 14 deletions
|
@ -223,27 +223,43 @@ fn match_log_level_str(s: &str) -> Result<LogLevel> {
|
||||||
fn aggregate_global_loglevel(matches: &ArgMatches, config: Option<&Configuration>)
|
fn aggregate_global_loglevel(matches: &ArgMatches, config: Option<&Configuration>)
|
||||||
-> Result<LogLevel>
|
-> Result<LogLevel>
|
||||||
{
|
{
|
||||||
match config {
|
fn get_arg_loglevel(matches: &ArgMatches) -> Result<Option<LogLevel>> {
|
||||||
Some(cfg) => match cfg.read("imag.logging.level") {
|
if matches.is_present(Runtime::arg_debugging_name()) {
|
||||||
|
return Ok(Some(LogLevel::Debug))
|
||||||
|
}
|
||||||
|
|
||||||
|
if matches.is_present(Runtime::arg_verbosity_name()) {
|
||||||
|
return Ok(Some(LogLevel::Info))
|
||||||
|
}
|
||||||
|
|
||||||
|
match matches.value_of(Runtime::arg_verbosity_name()) {
|
||||||
|
Some(v) => match_log_level_str(v).map(Some),
|
||||||
|
None => Ok(None),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(cfg) = config {
|
||||||
|
let cfg_loglevel = match cfg.read("imag.logging.level") {
|
||||||
Ok(Some(&Value::String(ref s))) => match_log_level_str(s),
|
Ok(Some(&Value::String(ref s))) => match_log_level_str(s),
|
||||||
Ok(Some(_)) => {
|
Ok(Some(_)) => {
|
||||||
let path = "imag.logging.level".to_owned();
|
let path = "imag.logging.level".to_owned();
|
||||||
let ty = "String";
|
let ty = "String";
|
||||||
Err(RE::from_kind(EK::ConfigTypeError(path, ty)))
|
return Err(RE::from_kind(EK::ConfigTypeError(path, ty)))
|
||||||
},
|
},
|
||||||
Ok(None) => Err(RE::from_kind(EK::GlobalLogLevelConfigMissing)),
|
Ok(None) => return Err(RE::from_kind(EK::GlobalLogLevelConfigMissing)),
|
||||||
Err(e) => Err(e).map_err(From::from),
|
Err(e) => return Err(e).map_err(From::from),
|
||||||
},
|
}?;
|
||||||
None => {
|
|
||||||
if matches.is_present(Runtime::arg_debugging_name()) {
|
|
||||||
return Ok(LogLevel::Debug)
|
|
||||||
}
|
|
||||||
|
|
||||||
matches
|
if let Some(cli_loglevel) = get_arg_loglevel(matches)? {
|
||||||
.value_of(Runtime::arg_verbosity_name())
|
if cli_loglevel > cfg_loglevel {
|
||||||
.map(match_log_level_str)
|
return Ok(cli_loglevel)
|
||||||
.unwrap_or(Ok(LogLevel::Info))
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(cfg_loglevel)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
get_arg_loglevel(matches).map(|o| o.unwrap_or(LogLevel::Info))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue