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:
Matthias Beyer 2017-10-15 19:45:34 +02:00
parent 704c01b2c9
commit 817933c99f

View file

@ -223,27 +223,43 @@ fn match_log_level_str(s: &str) -> Result<LogLevel> {
fn aggregate_global_loglevel(matches: &ArgMatches, config: Option<&Configuration>)
-> Result<LogLevel>
{
match config {
Some(cfg) => match cfg.read("imag.logging.level") {
fn get_arg_loglevel(matches: &ArgMatches) -> Result<Option<LogLevel>> {
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(_)) => {
let path = "imag.logging.level".to_owned();
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)),
Err(e) => Err(e).map_err(From::from),
},
None => {
if matches.is_present(Runtime::arg_debugging_name()) {
return Ok(LogLevel::Debug)
}
Ok(None) => return Err(RE::from_kind(EK::GlobalLogLevelConfigMissing)),
Err(e) => return Err(e).map_err(From::from),
}?;
matches
.value_of(Runtime::arg_verbosity_name())
.map(match_log_level_str)
.unwrap_or(Ok(LogLevel::Info))
if let Some(cli_loglevel) = get_arg_loglevel(matches)? {
if cli_loglevel > cfg_loglevel {
return Ok(cli_loglevel)
}
}
Ok(cfg_loglevel)
} else {
get_arg_loglevel(matches).map(|o| o.unwrap_or(LogLevel::Info))
}
}