diff options
Diffstat (limited to 'src/logging.rs')
-rw-r--r-- | src/logging.rs | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/logging.rs b/src/logging.rs index 1fe769fd..ff2a7735 100644 --- a/src/logging.rs +++ b/src/logging.rs @@ -23,14 +23,14 @@ use std::io; use cli; pub struct Logger<T> { - level: log::LogLevelFilter, + level: log::LevelFilter, output: sync::Mutex<T> } impl<T: Send + io::Write> Logger<T> { // False positive, see: https://github.com/rust-lang-nursery/rust-clippy/issues/734 #[cfg_attr(feature = "clippy", allow(new_ret_no_self))] - pub fn new(output: T, level: log::LogLevelFilter) -> Logger<io::LineWriter<T>> { + pub fn new(output: T, level: log::LevelFilter) -> Logger<io::LineWriter<T>> { Logger { level: level, output: sync::Mutex::new(io::LineWriter::new(output)) @@ -39,28 +39,27 @@ impl<T: Send + io::Write> Logger<T> { } impl<T: Send + io::Write> log::Log for Logger<T> { - fn enabled(&self, metadata: &log::LogMetadata) -> bool { + fn enabled(&self, metadata: &log::Metadata) -> bool { metadata.level() <= self.level } - fn log(&self, record: &log::LogRecord) { + fn log(&self, record: &log::Record) { if self.enabled(record.metadata()) && record.target().starts_with("alacritty") { if let Ok(ref mut writer) = self.output.lock() { writer.write_all(format!("{}\n", record.args()).as_ref()).expect("Error while logging!"); } } } + + fn flush(&self) {} } pub fn initialize(options: &cli::Options) -> Result<(), log::SetLoggerError> { // 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() + ::env_logger::try_init() } else { - log::set_logger(|max_log_level| { - max_log_level.set(options.log_level); - Box::new(Logger::new(io::stdout(), options.log_level)) - }) + log::set_boxed_logger(Box::new(Logger::new(io::stdout(), options.log_level))) } } |