From d6aa42bd60aefbacebc21a80132abcd544638f6b Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 25 Mar 2016 19:42:10 +0100 Subject: [PATCH] Move logger initialization to earliest possible point --- imag-counter/src/main.rs | 2 -- imag-link/src/main.rs | 2 -- imag-store/src/main.rs | 2 -- imag-tag/src/main.rs | 2 -- imag-view/src/main.rs | 2 -- libimagrt/src/runtime.rs | 12 +++++++++--- 6 files changed, 9 insertions(+), 13 deletions(-) diff --git a/imag-counter/src/main.rs b/imag-counter/src/main.rs index 8e62be23..326bff1d 100644 --- a/imag-counter/src/main.rs +++ b/imag-counter/src/main.rs @@ -49,8 +49,6 @@ fn main() { } }; - rt.init_logger(); - debug!("Hello. Logging was just enabled"); debug!("I already set up the Runtime object and build the commandline interface parser."); debug!("Lets get rollin' ..."); diff --git a/imag-link/src/main.rs b/imag-link/src/main.rs index 5934987a..640d20a0 100644 --- a/imag-link/src/main.rs +++ b/imag-link/src/main.rs @@ -40,8 +40,6 @@ fn main() { } }; - rt.init_logger(); - debug!("Hello. Logging was just enabled"); debug!("I already set up the Runtime object and build the commandline interface parser."); debug!("Lets get rollin' ..."); diff --git a/imag-store/src/main.rs b/imag-store/src/main.rs index 4533c338..702b5afd 100644 --- a/imag-store/src/main.rs +++ b/imag-store/src/main.rs @@ -41,8 +41,6 @@ fn main() { } }; - rt.init_logger(); - debug!("Hello. Logging was just enabled"); debug!("I already set up the Runtime object and build the commandline interface parser."); debug!("Lets get rollin' ..."); diff --git a/imag-tag/src/main.rs b/imag-tag/src/main.rs index 52c39168..07739c11 100644 --- a/imag-tag/src/main.rs +++ b/imag-tag/src/main.rs @@ -37,8 +37,6 @@ fn main() { } }; - rt.init_logger(); - debug!("Hello. Logging was just enabled"); debug!("I already set up the Runtime object and build the commandline interface parser."); debug!("Lets get rollin' ..."); diff --git a/imag-view/src/main.rs b/imag-view/src/main.rs index 1b4d5222..2d41b810 100644 --- a/imag-view/src/main.rs +++ b/imag-view/src/main.rs @@ -45,8 +45,6 @@ fn main() { } }; - rt.init_logger(); - debug!("Hello. Logging was just enabled"); debug!("I already set up the Runtime object and build the commandline interface parser."); debug!("Lets get rollin' ..."); diff --git a/libimagrt/src/runtime.rs b/libimagrt/src/runtime.rs index d401940e..746bf100 100644 --- a/libimagrt/src/runtime.rs +++ b/libimagrt/src/runtime.rs @@ -39,6 +39,12 @@ impl<'a> Runtime<'a> { use configuration::error::ConfigErrorKind; let matches = cli_spec.get_matches(); + + let is_debugging = matches.is_present("debugging"); + let is_verbose = matches.is_present("verbosity"); + + Runtime::init_logger(is_debugging, is_verbose); + let rtp : PathBuf = matches.value_of("runtimepath") .map(PathBuf::from) .unwrap_or_else(|| { @@ -153,10 +159,10 @@ impl<'a> Runtime<'a> { /** * Initialize the internal logger */ - pub fn init_logger(&self) { - let lvl = if self.is_debugging() { + fn init_logger(is_debugging: bool, is_verbose: bool) { + let lvl = if is_debugging { LogLevelFilter::Debug - } else if self.is_verbose() { + } else if is_verbose { LogLevelFilter::Info } else { LogLevelFilter::Error