Merge pull request #1149 from matthiasbeyer/libimagrt/remove-logging-format-overrides

Remove override functionality for logging formats
This commit is contained in:
Matthias Beyer 2017-10-16 10:11:28 +02:00 committed by GitHub
commit e7aa5af9be
3 changed files with 21 additions and 123 deletions

View File

@ -337,13 +337,6 @@ fn forward_commandline_arguments(m: &ArgMatches, scmd: &mut Vec<String>) {
Runtime::arg_generate_compl(), m , scmd);
push(None , Runtime::arg_logdest_name() , m , scmd);
push(None , Runtime::arg_override_module_logging_setting_name() , m , scmd);
push(None , Runtime::arg_override_trace_logging_format() , m , scmd);
push(None , Runtime::arg_override_debug_logging_format() , m , scmd);
push(None , Runtime::arg_override_info_logging_format() , m , scmd);
push(None , Runtime::arg_override_warn_logging_format() , m , scmd);
push(None , Runtime::arg_override_error_logging_format() , m , scmd);
}

View File

@ -86,23 +86,23 @@ impl ImagLogger {
::libimaginteraction::format::register_all_format_helpers(&mut handlebars);
{
let fmt = try!(aggregate_global_format_trace(matches, config));
let fmt = try!(aggregate_global_format_trace(config));
try!(handlebars.register_template_string("TRACE", fmt)); // name must be uppercase
}
{
let fmt = try!(aggregate_global_format_debug(matches, config));
let fmt = try!(aggregate_global_format_debug(config));
try!(handlebars.register_template_string("DEBUG", fmt)); // name must be uppercase
}
{
let fmt = try!(aggregate_global_format_info(matches, config));
let fmt = try!(aggregate_global_format_info(config));
try!(handlebars.register_template_string("INFO", fmt)); // name must be uppercase
}
{
let fmt = try!(aggregate_global_format_warn(matches, config));
let fmt = try!(aggregate_global_format_warn(config));
try!(handlebars.register_template_string("WARN", fmt)); // name must be uppercase
}
{
let fmt = try!(aggregate_global_format_error(matches, config));
let fmt = try!(aggregate_global_format_error(config));
try!(handlebars.register_template_string("ERROR", fmt)); // name must be uppercase
}
@ -333,77 +333,54 @@ fn aggregate_global_destinations(matches: &ArgMatches, config: Option<&Configura
}
}
#[inline]
fn aggregate_global_format(
read_str: &str,
cli_match_name: &str,
error_kind_if_missing: EK,
matches: &ArgMatches,
config: Option<&Configuration>
)
-> Result<String>
{
match config {
Some(cfg) => match cfg.read(read_str) {
macro_rules! aggregate_global_format {
($read_str:expr, $error_kind_if_missing:expr, $config:expr) => {
match try!($config.ok_or(RE::from_kind($error_kind_if_missing))).read($read_str) {
Ok(Some(&Value::String(ref s))) => Ok(s.clone()),
Ok(Some(_)) => Err(RE::from_kind(EK::ConfigTypeError(read_str.to_owned(), "String"))),
Ok(None) => Err(RE::from_kind(error_kind_if_missing)),
Ok(Some(_)) => Err(RE::from_kind(EK::ConfigTypeError($read_str.to_owned(), "String"))),
Ok(None) => Err(RE::from_kind($error_kind_if_missing)),
Err(e) => Err(e).map_err(From::from),
},
None => match matches.value_of(cli_match_name).map(String::from) {
Some(s) => Ok(s),
None => Err(RE::from_kind(error_kind_if_missing))
}
}
};
}
fn aggregate_global_format_trace(matches: &ArgMatches, config: Option<&Configuration>)
fn aggregate_global_format_trace(config: Option<&Configuration>)
-> Result<String>
{
aggregate_global_format("imag.logging.format.trace",
Runtime::arg_override_trace_logging_format(),
aggregate_global_format!("imag.logging.format.trace",
EK::ConfigMissingLoggingFormatTrace,
matches,
config)
}
fn aggregate_global_format_debug(matches: &ArgMatches, config: Option<&Configuration>)
fn aggregate_global_format_debug(config: Option<&Configuration>)
-> Result<String>
{
aggregate_global_format("imag.logging.format.debug",
Runtime::arg_override_debug_logging_format(),
aggregate_global_format!("imag.logging.format.debug",
EK::ConfigMissingLoggingFormatDebug,
matches,
config)
}
fn aggregate_global_format_info(matches: &ArgMatches, config: Option<&Configuration>)
fn aggregate_global_format_info(config: Option<&Configuration>)
-> Result<String>
{
aggregate_global_format("imag.logging.format.info",
Runtime::arg_override_info_logging_format(),
aggregate_global_format!("imag.logging.format.info",
EK::ConfigMissingLoggingFormatInfo,
matches,
config)
}
fn aggregate_global_format_warn(matches: &ArgMatches, config: Option<&Configuration>)
fn aggregate_global_format_warn(config: Option<&Configuration>)
-> Result<String>
{
aggregate_global_format("imag.logging.format.warn",
Runtime::arg_override_warn_logging_format(),
aggregate_global_format!("imag.logging.format.warn",
EK::ConfigMissingLoggingFormatWarn,
matches,
config)
}
fn aggregate_global_format_error(matches: &ArgMatches, config: Option<&Configuration>)
fn aggregate_global_format_error(config: Option<&Configuration>)
-> Result<String>
{
aggregate_global_format("imag.logging.format.error",
Runtime::arg_override_error_logging_format(),
aggregate_global_format!("imag.logging.format.error",
EK::ConfigMissingLoggingFormatError,
matches,
config)
}

View File

@ -255,54 +255,6 @@ impl<'a> Runtime<'a> {
.takes_value(true)
.value_name("LOGDESTS"))
.arg(Arg::with_name(Runtime::arg_override_module_logging_setting_name())
.long(Runtime::arg_override_module_logging_setting_name())
.help("Override a module logging setting for one module. Format: <modulename>=<setting>=<value>, whereas <setting> is either 'enabled', 'level' or 'destinations' - This commandline argument is CURRENTLY NOT IMPLEMENTED")
.multiple(true)
.required(false)
.takes_value(true)
.value_name("SPEC"))
.arg(Arg::with_name(Runtime::arg_override_trace_logging_format())
.long(Runtime::arg_override_trace_logging_format())
.help("Override the logging format for the trace logging")
.multiple(false)
.required(false)
.takes_value(true)
.value_name("FMT"))
.arg(Arg::with_name(Runtime::arg_override_debug_logging_format())
.long(Runtime::arg_override_debug_logging_format())
.help("Override the logging format for the debug logging")
.multiple(false)
.required(false)
.takes_value(true)
.value_name("FMT"))
.arg(Arg::with_name(Runtime::arg_override_info_logging_format())
.long(Runtime::arg_override_info_logging_format())
.help("Override the logging format for the info logging")
.multiple(false)
.required(false)
.takes_value(true)
.value_name("FMT"))
.arg(Arg::with_name(Runtime::arg_override_warn_logging_format())
.long(Runtime::arg_override_warn_logging_format())
.help("Override the logging format for the warn logging")
.multiple(false)
.required(false)
.takes_value(true)
.value_name("FMT"))
.arg(Arg::with_name(Runtime::arg_override_error_logging_format())
.long(Runtime::arg_override_error_logging_format())
.help("Override the logging format for the error logging")
.multiple(false)
.required(false)
.takes_value(true)
.value_name("FMT"))
}
/// Get the argument names of the Runtime which are available
@ -392,30 +344,6 @@ impl<'a> Runtime<'a> {
"logging-destinations"
}
pub fn arg_override_module_logging_setting_name() -> &'static str {
"override-module-log-setting"
}
pub fn arg_override_trace_logging_format() -> &'static str {
"override-logging-format-trace"
}
pub fn arg_override_debug_logging_format() -> &'static str {
"override-logging-format-debug"
}
pub fn arg_override_info_logging_format() -> &'static str {
"override-logging-format-info"
}
pub fn arg_override_warn_logging_format() -> &'static str {
"override-logging-format-warn"
}
pub fn arg_override_error_logging_format() -> &'static str {
"override-logging-format-error"
}
/// Initialize the internal logger
fn init_logger(matches: &ArgMatches, config: Option<&Configuration>) {
use std::env::var as env_var;