Remove override functionality for logging formats
This commit is contained in:
parent
704c01b2c9
commit
e5d93f5ff3
2 changed files with 21 additions and 116 deletions
|
@ -86,23 +86,23 @@ impl ImagLogger {
|
||||||
::libimaginteraction::format::register_all_format_helpers(&mut handlebars);
|
::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
|
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
|
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
|
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
|
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
|
try!(handlebars.register_template_string("ERROR", fmt)); // name must be uppercase
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -317,77 +317,54 @@ fn aggregate_global_destinations(matches: &ArgMatches, config: Option<&Configura
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
macro_rules! aggregate_global_format {
|
||||||
fn aggregate_global_format(
|
($read_str:expr, $error_kind_if_missing:expr, $config:expr) => {
|
||||||
read_str: &str,
|
match try!($config.ok_or(RE::from_kind($error_kind_if_missing))).read($read_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) {
|
|
||||||
Ok(Some(&Value::String(ref s))) => Ok(s.clone()),
|
Ok(Some(&Value::String(ref s))) => Ok(s.clone()),
|
||||||
Ok(Some(_)) => Err(RE::from_kind(EK::ConfigTypeError(read_str.to_owned(), "String"))),
|
Ok(Some(_)) => Err(RE::from_kind(EK::ConfigTypeError($read_str.to_owned(), "String"))),
|
||||||
Ok(None) => Err(RE::from_kind(error_kind_if_missing)),
|
Ok(None) => Err(RE::from_kind($error_kind_if_missing)),
|
||||||
Err(e) => Err(e).map_err(From::from),
|
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>
|
-> Result<String>
|
||||||
{
|
{
|
||||||
aggregate_global_format("imag.logging.format.trace",
|
aggregate_global_format!("imag.logging.format.trace",
|
||||||
Runtime::arg_override_trace_logging_format(),
|
|
||||||
EK::ConfigMissingLoggingFormatTrace,
|
EK::ConfigMissingLoggingFormatTrace,
|
||||||
matches,
|
|
||||||
config)
|
config)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn aggregate_global_format_debug(matches: &ArgMatches, config: Option<&Configuration>)
|
fn aggregate_global_format_debug(config: Option<&Configuration>)
|
||||||
-> Result<String>
|
-> Result<String>
|
||||||
{
|
{
|
||||||
aggregate_global_format("imag.logging.format.debug",
|
aggregate_global_format!("imag.logging.format.debug",
|
||||||
Runtime::arg_override_debug_logging_format(),
|
|
||||||
EK::ConfigMissingLoggingFormatDebug,
|
EK::ConfigMissingLoggingFormatDebug,
|
||||||
matches,
|
|
||||||
config)
|
config)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn aggregate_global_format_info(matches: &ArgMatches, config: Option<&Configuration>)
|
fn aggregate_global_format_info(config: Option<&Configuration>)
|
||||||
-> Result<String>
|
-> Result<String>
|
||||||
{
|
{
|
||||||
aggregate_global_format("imag.logging.format.info",
|
aggregate_global_format!("imag.logging.format.info",
|
||||||
Runtime::arg_override_info_logging_format(),
|
|
||||||
EK::ConfigMissingLoggingFormatInfo,
|
EK::ConfigMissingLoggingFormatInfo,
|
||||||
matches,
|
|
||||||
config)
|
config)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn aggregate_global_format_warn(matches: &ArgMatches, config: Option<&Configuration>)
|
fn aggregate_global_format_warn(config: Option<&Configuration>)
|
||||||
-> Result<String>
|
-> Result<String>
|
||||||
{
|
{
|
||||||
aggregate_global_format("imag.logging.format.warn",
|
aggregate_global_format!("imag.logging.format.warn",
|
||||||
Runtime::arg_override_warn_logging_format(),
|
|
||||||
EK::ConfigMissingLoggingFormatWarn,
|
EK::ConfigMissingLoggingFormatWarn,
|
||||||
matches,
|
|
||||||
config)
|
config)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn aggregate_global_format_error(matches: &ArgMatches, config: Option<&Configuration>)
|
fn aggregate_global_format_error(config: Option<&Configuration>)
|
||||||
-> Result<String>
|
-> Result<String>
|
||||||
{
|
{
|
||||||
aggregate_global_format("imag.logging.format.error",
|
aggregate_global_format!("imag.logging.format.error",
|
||||||
Runtime::arg_override_error_logging_format(),
|
|
||||||
EK::ConfigMissingLoggingFormatError,
|
EK::ConfigMissingLoggingFormatError,
|
||||||
matches,
|
|
||||||
config)
|
config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -255,54 +255,6 @@ impl<'a> Runtime<'a> {
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.value_name("LOGDESTS"))
|
.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
|
/// Get the argument names of the Runtime which are available
|
||||||
|
@ -392,30 +344,6 @@ impl<'a> Runtime<'a> {
|
||||||
"logging-destinations"
|
"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
|
/// Initialize the internal logger
|
||||||
fn init_logger(matches: &ArgMatches, config: Option<&Configuration>) {
|
fn init_logger(matches: &ArgMatches, config: Option<&Configuration>) {
|
||||||
use std::env::var as env_var;
|
use std::env::var as env_var;
|
||||||
|
|
Loading…
Reference in a new issue