Merge pull request #433 from matthiasbeyer/libimagrt/env_logger_fallback
Libimagrt/env logger fallback
This commit is contained in:
commit
27ded75c60
3 changed files with 25 additions and 16 deletions
|
@ -5,6 +5,7 @@ authors = ["Matthias Beyer <mail@beyermatthias.de>"]
|
|||
|
||||
[dependencies]
|
||||
clap = "2.1.1"
|
||||
env_logger = "0.3"
|
||||
toml = "0.1.27"
|
||||
log = "0.3"
|
||||
xdg-basedir = "0.2.2"
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#[macro_use] extern crate log;
|
||||
#[macro_use] extern crate itertools;
|
||||
#[cfg(unix)] extern crate xdg_basedir;
|
||||
extern crate env_logger;
|
||||
extern crate tempfile;
|
||||
extern crate ansi_term;
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue