diff options
author | Christian Duerr <chrisduerr@users.noreply.github.com> | 2019-05-10 11:36:16 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-10 11:36:16 +0000 |
commit | 5d173f6df3b20308eb318cef4b58147b2197d5f9 (patch) | |
tree | 05638837bef25d65a818253814331a4f429f57ac /alacritty/src/logging.rs | |
parent | 7738c52ed4eb177ead9f43d14207ecb129cfe617 (diff) | |
download | r-alacritty-5d173f6df3b20308eb318cef4b58147b2197d5f9.tar.gz r-alacritty-5d173f6df3b20308eb318cef4b58147b2197d5f9.tar.bz2 r-alacritty-5d173f6df3b20308eb318cef4b58147b2197d5f9.zip |
Refactor config parsing files
This is a large refactor of the config parsing structure, attempting to
reduce the size of the file a bit by splitting it up into different
modules with more specific purposes.
This also fixes #2279.
Diffstat (limited to 'alacritty/src/logging.rs')
-rw-r--r-- | alacritty/src/logging.rs | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/alacritty/src/logging.rs b/alacritty/src/logging.rs index 0b67440d..d4cb70c5 100644 --- a/alacritty/src/logging.rs +++ b/alacritty/src/logging.rs @@ -29,23 +29,26 @@ use crossbeam_channel::Sender; use log::{self, Level}; use time; -use alacritty_terminal::config::Options; use alacritty_terminal::message_bar::Message; use alacritty_terminal::term::color; +use crate::cli::Options; + const ALACRITTY_LOG_ENV: &str = "ALACRITTY_LOG"; pub fn initialize( options: &Options, message_tx: Sender<Message>, ) -> Result<Option<PathBuf>, log::SetLoggerError> { + log::set_max_level(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::try_init()?; Ok(None) } else { - let logger = Logger::new(options.log_level, message_tx); + let logger = Logger::new(message_tx); let path = logger.file_path(); log::set_boxed_logger(Box::new(logger))?; Ok(path) @@ -53,22 +56,17 @@ pub fn initialize( } pub struct Logger { - level: log::LevelFilter, logfile: Mutex<OnDemandLogFile>, stdout: Mutex<LineWriter<Stdout>>, message_tx: Sender<Message>, } impl Logger { - // False positive, see: https://github.com/rust-lang-nursery/rust-clippy/issues/734 - #[allow(clippy::new_ret_no_self)] - fn new(level: log::LevelFilter, message_tx: Sender<Message>) -> Self { - log::set_max_level(level); - + fn new(message_tx: Sender<Message>) -> Self { let logfile = Mutex::new(OnDemandLogFile::new()); let stdout = Mutex::new(LineWriter::new(io::stdout())); - Logger { level, logfile, stdout, message_tx } + Logger { logfile, stdout, message_tx } } fn file_path(&self) -> Option<PathBuf> { @@ -82,7 +80,7 @@ impl Logger { impl log::Log for Logger { fn enabled(&self, metadata: &log::Metadata<'_>) -> bool { - metadata.level() <= self.level + metadata.level() <= log::max_level() } fn log(&self, record: &log::Record<'_>) { |