diff --git a/src/config.rs b/src/config.rs index 64051c7d..2f0c9923 100644 --- a/src/config.rs +++ b/src/config.rs @@ -91,49 +91,49 @@ impl ConfigBuilder { } /// Set at which level and above (more verbose) the level itself shall be logged (default is Error) - pub fn set_max_level<'a>(&'a mut self, level: LevelFilter) -> &'a mut ConfigBuilder { + pub fn set_max_level(&mut self, level: LevelFilter) -> &mut ConfigBuilder { self.0.level = level; self } /// Set at which level and above (more verbose) the current time shall be logged (default is Error) - pub fn set_time_level<'a>(&'a mut self, time: LevelFilter) -> &'a mut ConfigBuilder { + pub fn set_time_level(&mut self, time: LevelFilter) -> &mut ConfigBuilder { self.0.time = time; self } /// Set at which level and above (more verbose) the thread id shall be logged. (default is Debug) - pub fn set_thread_level<'a>(&'a mut self, thread: LevelFilter) -> &'a mut ConfigBuilder { + pub fn set_thread_level(&mut self, thread: LevelFilter) -> &mut ConfigBuilder { self.0.thread = thread; self } /// Set at which level and above (more verbose) the target shall be logged. (default is Debug) - pub fn set_target_level<'a>(&'a mut self, target: LevelFilter) -> &'a mut ConfigBuilder { + pub fn set_target_level(&mut self, target: LevelFilter) -> &mut ConfigBuilder { self.0.target = target; self } /// Set at which level and above (more verbose) a source code reference shall be logged (default is Trace) - pub fn set_location_level<'a>(&'a mut self, location: LevelFilter) -> &'a mut ConfigBuilder { + pub fn set_location_level(&mut self, location: LevelFilter) -> &mut ConfigBuilder { self.0.location = location; self } /// Set how the levels should be padded, when logging (default is Left) - pub fn set_level_padding<'a>(&'a mut self, padding: LevelPadding) -> &'a mut ConfigBuilder { + pub fn set_level_padding(&mut self, padding: LevelPadding) -> &mut ConfigBuilder { self.0.level_padding = padding; self } /// Set how the thread should be padded - pub fn set_thread_padding<'a>(&'a mut self, padding: ThreadPadding) -> &'a mut ConfigBuilder { + pub fn set_thread_padding(&mut self, padding: ThreadPadding) -> &mut ConfigBuilder { self.0.thread_padding = padding; self } /// Set the mode for logging the thread - pub fn set_thread_mode<'a>(&'a mut self, mode: ThreadLogMode) -> &'a mut ConfigBuilder { + pub fn set_thread_mode(&mut self, mode: ThreadLogMode) -> &mut ConfigBuilder { self.0.thread_log_mode = mode; self } @@ -141,11 +141,7 @@ impl ConfigBuilder { /// Set the color used for printing the level (if the logger supports it), /// or None to use the default foreground color #[cfg(feature = "termcolor")] - pub fn set_level_color<'a>( - &'a mut self, - level: Level, - color: Option, - ) -> &'a mut ConfigBuilder { + pub fn set_level_color(&mut self, level: Level, color: Option) -> &mut ConfigBuilder { self.0.level_color[level as usize] = color; self } @@ -153,10 +149,7 @@ impl ConfigBuilder { /// Set time chrono [strftime] format string. /// /// [strftime]: https://docs.rs/chrono/0.4.0/chrono/format/strftime/index.html#specifiers - pub fn set_time_format_str<'a>( - &'a mut self, - time_format: &'static str, - ) -> &'a mut ConfigBuilder { + pub fn set_time_format_str(&mut self, time_format: &'static str) -> &mut ConfigBuilder { self.0.time_format = Cow::Borrowed(time_format); self } @@ -164,19 +157,19 @@ impl ConfigBuilder { /// Set time chrono [strftime] format string. /// /// [strftime]: https://docs.rs/chrono/0.4.0/chrono/format/strftime/index.html#specifiers - pub fn set_time_format<'a>(&'a mut self, time_format: String) -> &'a mut ConfigBuilder { + pub fn set_time_format(&mut self, time_format: String) -> &mut ConfigBuilder { self.0.time_format = Cow::Owned(time_format); self } /// Set offset used for logging time (default is 0) - pub fn set_time_offset<'a>(&'a mut self, time_offset: FixedOffset) -> &'a mut ConfigBuilder { + pub fn set_time_offset(&mut self, time_offset: FixedOffset) -> &mut ConfigBuilder { self.0.time_offset = time_offset; self } /// set if you log in local timezone or UTC (default is UTC) - pub fn set_time_to_local<'a>(&'a mut self, local: bool) -> &'a mut ConfigBuilder { + pub fn set_time_to_local(&mut self, local: bool) -> &mut ConfigBuilder { self.0.time_local = local; self } @@ -185,10 +178,7 @@ impl ConfigBuilder { /// If any are specified, only records from modules starting with one of these entries will be printed /// /// For example, `add_filter_allow_str("tokio::uds")` would allow only logging from the `tokio` crates `uds` module. - pub fn add_filter_allow_str<'a>( - &'a mut self, - filter_allow: &'static str, - ) -> &'a mut ConfigBuilder { + pub fn add_filter_allow_str(&mut self, filter_allow: &'static str) -> &mut ConfigBuilder { let mut list = Vec::from(&*self.0.filter_allow); list.push(Cow::Borrowed(filter_allow)); self.0.filter_allow = Cow::Owned(list); @@ -199,7 +189,7 @@ impl ConfigBuilder { /// If any are specified, only records from modules starting with one of these entries will be printed /// /// For example, `add_filter_allow(format!("{}{}","tokio", "uds"))` would allow only logging from the `tokio` crates `uds` module. - pub fn add_filter_allow<'a>(&'a mut self, filter_allow: String) -> &'a mut ConfigBuilder { + pub fn add_filter_allow(&mut self, filter_allow: String) -> &mut ConfigBuilder { let mut list = Vec::from(&*self.0.filter_allow); list.push(Cow::Owned(filter_allow)); self.0.filter_allow = Cow::Owned(list); @@ -208,7 +198,7 @@ impl ConfigBuilder { /// Clear allowed module filters. /// If none are specified, nothing is filtered out - pub fn clear_filter_allow<'a>(&'a mut self) -> &'a mut ConfigBuilder { + pub fn clear_filter_allow(&mut self) -> &mut ConfigBuilder { self.0.filter_allow = Cow::Borrowed(&[]); self } @@ -217,10 +207,7 @@ impl ConfigBuilder { /// If any are specified, records from modules starting with one of these entries will be ignored /// /// For example, `add_filter_ignore_str("tokio::uds")` would deny logging from the `tokio` crates `uds` module. - pub fn add_filter_ignore_str<'a>( - &'a mut self, - filter_ignore: &'static str, - ) -> &'a mut ConfigBuilder { + pub fn add_filter_ignore_str(&mut self, filter_ignore: &'static str) -> &mut ConfigBuilder { let mut list = Vec::from(&*self.0.filter_ignore); list.push(Cow::Borrowed(filter_ignore)); self.0.filter_ignore = Cow::Owned(list); @@ -231,7 +218,7 @@ impl ConfigBuilder { /// If any are specified, records from modules starting with one of these entries will be ignored /// /// For example, `add_filter_ignore(format!("{}{}","tokio", "uds"))` would deny logging from the `tokio` crates `uds` module. - pub fn add_filter_ignore<'a>(&'a mut self, filter_ignore: String) -> &'a mut ConfigBuilder { + pub fn add_filter_ignore(&mut self, filter_ignore: String) -> &mut ConfigBuilder { let mut list = Vec::from(&*self.0.filter_ignore); list.push(Cow::Owned(filter_ignore)); self.0.filter_ignore = Cow::Owned(list); @@ -240,7 +227,7 @@ impl ConfigBuilder { /// Clear ignore module filters. /// If none are specified, nothing is filtered - pub fn clear_filter_ignore<'a>(&'a mut self) -> &'a mut ConfigBuilder { + pub fn clear_filter_ignore(&mut self) -> &mut ConfigBuilder { self.0.filter_ignore = Cow::Borrowed(&[]); self } @@ -251,6 +238,12 @@ impl ConfigBuilder { } } +impl Default for ConfigBuilder { + fn default() -> Self { + ConfigBuilder::new() + } +} + impl Default for Config { fn default() -> Config { Config { diff --git a/src/loggers/comblog.rs b/src/loggers/comblog.rs index 693fa1a7..103b041d 100644 --- a/src/loggers/comblog.rs +++ b/src/loggers/comblog.rs @@ -84,7 +84,7 @@ impl CombinedLogger { Box::new(CombinedLogger { level: log_level, - logger: logger, + logger, }) } } diff --git a/src/loggers/logging.rs b/src/loggers/logging.rs index ef22fe6d..cb3b9e4b 100644 --- a/src/loggers/logging.rs +++ b/src/loggers/logging.rs @@ -1,5 +1,4 @@ use crate::{Config, LevelPadding, ThreadLogMode, ThreadPadding}; -use chrono; use log::{LevelFilter, Record}; use std::io::{Error, Write}; use std::thread; @@ -151,9 +150,9 @@ where pub fn should_skip(config: &Config, record: &Record<'_>) -> bool { // If a module path and allowed list are available match (record.target(), &*config.filter_allow) { - (path, allowed) if allowed.len() > 0 => { + (path, allowed) if !allowed.is_empty() => { // Check that the module path matches at least one allow filter - if let None = allowed.iter().find(|v| path.starts_with(&***v)) { + if !allowed.iter().any(|v| path.starts_with(&**v)) { // If not, skip any further writing return true; } @@ -163,9 +162,9 @@ pub fn should_skip(config: &Config, record: &Record<'_>) -> bool { // If a module path and ignore list are available match (record.target(), &*config.filter_ignore) { - (path, ignore) if ignore.len() > 0 => { + (path, ignore) if !ignore.is_empty() => { // Check that the module path does not match any ignore filters - if let Some(_) = ignore.iter().find(|v| path.starts_with(&***v)) { + if ignore.iter().any(|v| path.starts_with(&**v)) { // If not, skip any further writing return true; } @@ -173,5 +172,5 @@ pub fn should_skip(config: &Config, record: &Record<'_>) -> bool { _ => {} } - return false; + false } diff --git a/src/loggers/simplelog.rs b/src/loggers/simplelog.rs index 9dedc11f..f3a5773c 100644 --- a/src/loggers/simplelog.rs +++ b/src/loggers/simplelog.rs @@ -37,7 +37,7 @@ impl SimpleLogger { /// # } /// ``` pub fn init(log_level: LevelFilter, config: Config) -> Result<(), SetLoggerError> { - set_max_level(log_level.clone()); + set_max_level(log_level); set_boxed_logger(SimpleLogger::new(log_level, config)) } @@ -59,7 +59,7 @@ impl SimpleLogger { pub fn new(log_level: LevelFilter, config: Config) -> Box { Box::new(SimpleLogger { level: log_level, - config: config, + config, output_lock: Mutex::new(()), }) } diff --git a/src/loggers/termlog.rs b/src/loggers/termlog.rs index c1098452..cfdfb459 100644 --- a/src/loggers/termlog.rs +++ b/src/loggers/termlog.rs @@ -5,7 +5,6 @@ use log::{ }; use std::io::{Error, Write}; use std::sync::Mutex; -use termcolor; use termcolor::{ColorChoice, ColorSpec, StandardStream, WriteColor}; use super::logging::*; @@ -83,7 +82,7 @@ impl TermLogger { color_choice: ColorChoice, ) -> Result<(), SetLoggerError> { let logger = TermLogger::new(log_level, config, mode, color_choice); - set_max_level(log_level.clone()); + set_max_level(log_level); set_boxed_logger(logger)?; Ok(()) } @@ -133,7 +132,7 @@ impl TermLogger { Box::new(TermLogger { level: log_level, - config: config, + config, streams: Mutex::new(streams), }) } diff --git a/src/loggers/testlog.rs b/src/loggers/testlog.rs index 3a575016..2c616442 100644 --- a/src/loggers/testlog.rs +++ b/src/loggers/testlog.rs @@ -38,7 +38,7 @@ impl TestLogger { /// # } /// ``` pub fn init(log_level: LevelFilter, config: Config) -> Result<(), SetLoggerError> { - set_max_level(log_level.clone()); + set_max_level(log_level); set_boxed_logger(TestLogger::new(log_level, config)) } diff --git a/src/loggers/writelog.rs b/src/loggers/writelog.rs index aa163bd9..0624d8d2 100644 --- a/src/loggers/writelog.rs +++ b/src/loggers/writelog.rs @@ -36,7 +36,7 @@ impl WriteLogger { /// # } /// ``` pub fn init(log_level: LevelFilter, config: Config, writable: W) -> Result<(), SetLoggerError> { - set_max_level(log_level.clone()); + set_max_level(log_level); set_boxed_logger(WriteLogger::new(log_level, config, writable)) } @@ -59,7 +59,7 @@ impl WriteLogger { pub fn new(log_level: LevelFilter, config: Config, writable: W) -> Box> { Box::new(WriteLogger { level: log_level, - config: config, + config, writable: Mutex::new(writable), }) }