From 9a92f9091fa41e97dac7acb06181df748e04c807 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 24 May 2016 16:43:04 +0200 Subject: [PATCH] Add env_logger as fallback if IMAG_LOG_ENV is present --- libimagrt/src/runtime.rs | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/libimagrt/src/runtime.rs b/libimagrt/src/runtime.rs index 57540b76..ba520445 100644 --- a/libimagrt/src/runtime.rs +++ b/libimagrt/src/runtime.rs @@ -197,23 +197,30 @@ impl<'a> Runtime<'a> { * Initialize the internal logger */ fn init_logger(is_debugging: bool, is_verbose: bool) { - let lvl = if is_debugging { - LogLevelFilter::Debug - } else if is_verbose { - LogLevelFilter::Info - } else { - LogLevelFilter::Error - }; + use std::env::var as env_var; + use env_logger; - log::set_logger(|max_log_lvl| { - max_log_lvl.set(lvl); - debug!("Init logger with {}", lvl); - Box::new(ImagLogger::new(lvl.to_log_level().unwrap())) - }) - .map_err(|_| { - panic!("Could not setup logger"); - }) - .ok(); + if env_var("IMAG_LOG_ENV").is_ok() { + env_logger::init().unwrap(); + } else { + let lvl = if is_debugging { + LogLevelFilter::Debug + } else if is_verbose { + LogLevelFilter::Info + } else { + LogLevelFilter::Error + }; + + log::set_logger(|max_log_lvl| { + max_log_lvl.set(lvl); + debug!("Init logger with {}", lvl); + Box::new(ImagLogger::new(lvl.to_log_level().unwrap())) + }) + .map_err(|_| { + panic!("Could not setup logger"); + }) + .ok(); + } } /**