summaryrefslogtreecommitdiffstats
path: root/libimagrt
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2016-05-24 16:43:04 +0200
committerMatthias Beyer <mail@beyermatthias.de>2016-05-24 16:43:04 +0200
commit9a92f9091fa41e97dac7acb06181df748e04c807 (patch)
treee2bfca70ae863548c9c6530985c1b4ee34b862e2 /libimagrt
parent4066ae404831c7bbbe70a018c38ea2f50406fc0a (diff)
Add env_logger as fallback if IMAG_LOG_ENV is present
Diffstat (limited to 'libimagrt')
-rw-r--r--libimagrt/src/runtime.rs37
1 files changed, 22 insertions, 15 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
+ use std::env::var as env_var;
+ use env_logger;
+
+ if env_var("IMAG_LOG_ENV").is_ok() {
+ env_logger::init().unwrap();
} else {
- LogLevelFilter::Error
- };
+ 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();
+ 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();
+ }
}
/**