aboutsummaryrefslogtreecommitdiff
path: root/src/logging.rs
diff options
context:
space:
mode:
authorJoe Wilm <joe@jwilm.com>2017-10-08 15:42:38 -0700
committerJoe Wilm <jwilm@users.noreply.github.com>2017-10-08 22:20:58 -0700
commit619e8778196104adb26bc9e735245d330a98ff38 (patch)
tree8ab5ed2e0da8d170cf2f477d50a172e03fa239b9 /src/logging.rs
parent31d1087b8614ddd423a6c522d91a1d93a37cd92e (diff)
downloadalacritty-619e8778196104adb26bc9e735245d330a98ff38.tar.gz
alacritty-619e8778196104adb26bc9e735245d330a98ff38.zip
Add support for env_logger
When RUST_LOG environment variable is set, uses env_logger instead of our custom logger. This is desirable for debugging purposes.
Diffstat (limited to 'src/logging.rs')
-rw-r--r--src/logging.rs15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/logging.rs b/src/logging.rs
index 6b7a7968..4584b5f6 100644
--- a/src/logging.rs
+++ b/src/logging.rs
@@ -36,7 +36,6 @@ impl<T: Send + io::Write> Logger<T> {
}
}
-
impl<T: Send + io::Write> log::Log for Logger<T> {
fn enabled(&self, metadata: &log::LogMetadata) -> bool {
metadata.level() <= self.level
@@ -52,8 +51,14 @@ impl<T: Send + io::Write> log::Log for Logger<T> {
}
pub fn initialize(options: &cli::Options) -> Result<(), log::SetLoggerError> {
- log::set_logger(|max_log_level| {
- max_log_level.set(options.log_level);
- Box::new(Logger::new(io::stdout(), options.log_level))
- })
+ // Use env_logger if RUST_LOG environment variable is defined. Otherwise,
+ // use the alacritty-only logger.
+ if ::std::env::var("RUST_LOG").is_ok() {
+ ::env_logger::init()
+ } else {
+ log::set_logger(|max_log_level| {
+ max_log_level.set(options.log_level);
+ Box::new(Logger::new(io::stdout(), options.log_level))
+ })
+ }
}