Merge pull request #1150 from matthiasbeyer/libimagrt/override-logging-with-debug-flag

Fix: Overide logging with --debug
This commit is contained in:
Matthias Beyer 2017-10-15 23:28:10 +02:00 committed by GitHub
commit e43b524420

View file

@ -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()) { if let Some(cli_loglevel) = get_arg_loglevel(matches)? {
return Ok(LogLevel::Debug) if cli_loglevel > cfg_loglevel {
return Ok(cli_loglevel)
}
} }
matches Ok(cfg_loglevel)
.value_of(Runtime::arg_verbosity_name())
.map(match_log_level_str) } else {
.unwrap_or(Ok(LogLevel::Info)) get_arg_loglevel(matches).map(|o| o.unwrap_or(LogLevel::Info))
}
} }
} }