From 7f63334f3ce586ccd46075d557f53cd17c5e8659 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 28 Feb 2020 12:13:28 +0100 Subject: Remove module logging settings Signed-off-by: Matthias Beyer --- imagrc.toml | 140 ------------------------------------------------------------ 1 file changed, 140 deletions(-) diff --git a/imagrc.toml b/imagrc.toml index 33b7195b..a56d5cd2 100644 --- a/imagrc.toml +++ b/imagrc.toml @@ -93,146 +93,6 @@ info = "[imag]: {{message}}" warn = "[imag][{{bold level}}]: {{yellow message}}" error = "[imag][{{red level}}]: {{red message}}" -# -# The logging configurations for the modules of imag follow. -# -# Note that the `destinations` key is for _additional_ destinations to the -# default destination in `imag.logging.destinations`, not as replacement! So -# specifying stderr (`-`) in `imag.logging.destinations` _and_ in, for example, -# `imag.logging.modules.libimagstore` yields each log line twice, which might -# not be wanted behaviour. -# - -[imag.logging.modules.libimagutil] -destinations = [] -level = "debug" -enabled = true - -[imag.logging.modules.libimagtimeui] -destinations = [] -level = "debug" -enabled = true - -[imag.logging.modules.libimaginteraction] -destinations = [] -level = "debug" -enabled = true - -[imag.logging.modules.libimagstore] -destinations = [ "/tmp/libimagstore.log" ] -level = "trace" -enabled = true - -[imag.logging.modules.libimagrt] -destinations = [] -level = "debug" -enabled = true - -[imag.logging.modules.libimagerror] -destinations = [] -level = "debug" -enabled = true - -[imag.logging.modules.libimagbookmark] -destinations = [] -level = "debug" -enabled = true - -[imag.logging.modules.libimaghabit] -destinations = [] -level = "debug" -enabled = true - -[imag.logging.modules.libimagnotes] -destinations = [] -level = "debug" -enabled = true - -[imag.logging.modules.libimagcontact] -destinations = [] -level = "debug" -enabled = true - -[imag.logging.modules.libimagdiary] -destinations = [] -level = "debug" -enabled = true - -[imag.logging.modules.libimagtimetrack] -destinations = [] -level = "debug" -enabled = true - -[imag.logging.modules.libimaglog] -destinations = [] -level = "debug" -enabled = true - -[imag.logging.modules.libimagtodo] -destinations = [] -level = "debug" -enabled = true - -[imag.logging.modules.libimagmail] -destinations = [] -level = "debug" -enabled = true - -[imag.logging.modules.libimagentryfilter] -destinations = [] -level = "debug" -enabled = true - -[imag.logging.modules.libimagentrycategory] -destinations = [] -level = "debug" -enabled = true - -[imag.logging.modules.libimagentryannotation] -destinations = [] -level = "debug" -enabled = true - -[imag.logging.modules.libimagentrylink] -destinations = [] -level = "debug" -enabled = true - -[imag.logging.modules.libimagentrytag] -destinations = [] -level = "debug" -enabled = true - -[imag.logging.modules.libimagentrygps] -destinations = [] -level = "debug" -enabled = true - -[imag.logging.modules.libimagentryedit] -destinations = [] -level = "debug" -enabled = true - -[imag.logging.modules.libimagentryref] -destinations = [] -level = "debug" -enabled = true - -[imag.logging.modules.libimagentryview] -destinations = [] -level = "debug" -enabled = true - -[imag.logging.modules.libimagentrymarkdown] -destinations = [] -level = "debug" -enabled = true - -[imag.logging.modules.libimagentryutil] -destinations = [] -level = "debug" -enabled = true - # # Configuration options for the user interface # -- cgit v1.2.3 From 675820bb90ab5a751aa2db06b7ed339c262077a7 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 28 Feb 2020 12:13:34 +0100 Subject: Remove module-based logging This patch removes the module-based logging mechanism. This mechanism was introduced so that the configuration file is able to define which imag module logs what. This was a fine-granular setting, but most users won't actually touch it. It was more of a debugging-thing for developers. I rarely used it during development and it only introduced more headaches. It also was not updated (as in the configuration file missed a few modules, others where not removed despite the module did not exist anymore). All in all, it was rather unmaintained and just "too much". Thus, remove this thing completely. Developers know how to use grep. This also automatically fixes bugs where `imag --debug command` did not output any debugging log, but was expected to. Signed-off-by: Matthias Beyer --- lib/core/libimagrt/src/lib.rs | 1 - lib/core/libimagrt/src/logger.rs | 157 +++++---------------------------------- 2 files changed, 18 insertions(+), 140 deletions(-) diff --git a/lib/core/libimagrt/src/lib.rs b/lib/core/libimagrt/src/lib.rs index c5862858..f7c9f579 100644 --- a/lib/core/libimagrt/src/lib.rs +++ b/lib/core/libimagrt/src/lib.rs @@ -42,7 +42,6 @@ extern crate itertools; extern crate ansi_term; extern crate handlebars; extern crate serde; -#[macro_use] extern crate serde_derive; #[macro_use] extern crate failure; #[macro_use] extern crate toml_query; diff --git a/lib/core/libimagrt/src/logger.rs b/lib/core/libimagrt/src/logger.rs index c06f9fdc..c79f2ec2 100644 --- a/lib/core/libimagrt/src/logger.rs +++ b/lib/core/libimagrt/src/logger.rs @@ -37,8 +37,6 @@ use handlebars::Handlebars; use libimagerror::errors::ErrorMsg as EM; -type ModuleName = String; - #[derive(Debug)] enum LogDestination { Stderr, @@ -51,15 +49,6 @@ impl Default for LogDestination { } } -#[derive(Debug)] -struct ModuleSettings { - enabled: bool, - level: Option, - - #[allow(unused)] - destinations: Option>, -} - /// Logger implementation for `log` crate. #[derive(Debug)] pub struct ImagLogger { @@ -67,12 +56,6 @@ pub struct ImagLogger { #[allow(unused)] global_destinations : Vec, - // global_format_trace : , - // global_format_debug : , - // global_format_info : , - // global_format_warn : , - // global_format_error : , - module_settings : BTreeMap, handlebars: Handlebars, } @@ -100,7 +83,6 @@ impl ImagLogger { Ok(ImagLogger { global_loglevel : aggregate_global_loglevel(matches, config)?, global_destinations : aggregate_global_destinations(config)?, - module_settings : aggregate_module_settings(matches, config)?, handlebars, }) } @@ -153,45 +135,13 @@ impl Log for ImagLogger { } }; - // hack to get the right target configuration. - // If there is no element here, we use the empty string which automatically drops through - // to the unwrap_or_else() case - let record_target = record - .target() - .split("::") - .next() - .unwrap_or(""); - - self.module_settings - .get(record_target) - .map(|module_setting| { - let set = module_setting.enabled && - (module_setting.level.unwrap_or(self.global_loglevel) >= record.level() - || self.global_loglevel >= record.level()); - - if set { - if let Some(destinations) = &module_setting.destinations { - for d in destinations { - // If there's an error, we cannot do anything, can we? - log_to_destination(&d); - } - } - - for d in self.global_destinations.iter() { - // If there's an error, we cannot do anything, can we? - log_to_destination(&d); - } - } - }) - .unwrap_or_else(|| { - if self.global_loglevel >= record.level() { - // Yes, we log - for d in self.global_destinations.iter() { - // If there's an error, we cannot do anything, can we? - log_to_destination(&d); - } + if self.global_loglevel >= record.level() { + // Yes, we log + for d in self.global_destinations.iter() { + // If there's an error, we cannot do anything, can we? + log_to_destination(&d); } - }); + } } } @@ -264,22 +214,7 @@ fn translate_destination(raw: &str) -> Result { } } - -fn translate_destinations(raw: &[Value]) -> Result> { - raw.iter() - .map(|val| { - val.as_str() - .ok_or_else(|| "Type error at 'imag.logging.modules..destinations', expected Array") - .map_err(err_msg) - .map_err(Error::from) - .and_then(|s| translate_destination(s)) - }) - .collect() -} - -fn aggregate_global_destinations(config: Option<&Value>) - -> Result> -{ +fn aggregate_global_destinations(config: Option<&Value>) -> Result> { match config { None => Ok(vec![LogDestination::default()]), Some(cfg) => cfg @@ -292,7 +227,17 @@ fn aggregate_global_destinations(config: Option<&Value>) let msg = "Type error at 'imag.logging.destinations', expected 'Array'"; err_msg(msg) }) - .and_then(|val| translate_destinations(val)), + .and_then(|raw| { + raw.iter() + .map(|val| { + val.as_str() + .ok_or_else(|| "Type error at 'imag.logging.modules..destinations', expected Array") + .map_err(err_msg) + .map_err(Error::from) + .and_then(|s| translate_destination(s)) + }) + .collect::>>() + }), } } @@ -347,69 +292,3 @@ mod log_lvl_aggregate { } -fn aggregate_module_settings(_matches: &ArgMatches, config: Option<&Value>) - -> Result> -{ - use std::convert::TryInto; - - // - // We define helper types here for deserializing easily using typed toml-query functionality. - // - // We need the helper types because we cannot deserialize in the target types directly, because - // of the `File(Arc>)` variant in `LogDestination`, which would - // technically possible to deserialize the toml into the type, but it might be a bad idea. - // - // This code is idomatic enough for the conversions, so it is not a big painpoint. - // - - #[derive(Serialize, Deserialize, Debug)] - struct LoggingModuleConfig { - pub destinations: Option>, - pub level: Option, - pub enabled: bool, - } - - #[derive(Partial, Serialize, Deserialize, Debug)] - #[location = "imag.logging.modules"] - struct LoggingModuleConfigMap(BTreeMap); - - impl TryInto> for LoggingModuleConfigMap { - type Error = Error; - - fn try_into(self) -> Result> { - let mut map = BTreeMap::new(); - - for (key, value) in self.0.into_iter() { - map.insert(key, ModuleSettings { - enabled: value.enabled, - level: value.level.map(Into::into), - destinations: match value.destinations { - None => None, - Some(ds) => Some(ds - .iter() - .map(Deref::deref) - .map(translate_destination) // This is why we do this whole thing - .collect::>>()?) - }, - }); - } - - Ok(map) - } - } - - match config { - Some(cfg) => cfg.read_partial::()? - .ok_or_else(|| err_msg("Logging configuration missing"))? - .try_into() - .map_err(Error::from), - None => { - write!(stderr(), "No Configuration.").ok(); - write!(stderr(), "cannot find module-settings for logging.").ok(); - write!(stderr(), "Will use global defaults").ok(); - - Ok(BTreeMap::new()) - } - } -} - -- cgit v1.2.3