Skip to content

Commit

Permalink
fix clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
Drakulix committed Mar 27, 2021
1 parent 33c8ac9 commit e741dd8
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 47 deletions.
57 changes: 25 additions & 32 deletions src/config.rs
Expand Up @@ -91,92 +91,85 @@ 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
}

/// 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<Color>,
) -> &'a mut ConfigBuilder {
pub fn set_level_color(&mut self, level: Level, color: Option<Color>) -> &mut ConfigBuilder {
self.0.level_color[level as usize] = color;
self
}

/// 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
}

/// 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
}
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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
}
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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
}
Expand All @@ -251,6 +238,12 @@ impl ConfigBuilder {
}
}

impl Default for ConfigBuilder {
fn default() -> Self {
ConfigBuilder::new()
}
}

impl Default for Config {
fn default() -> Config {
Config {
Expand Down
2 changes: 1 addition & 1 deletion src/loggers/comblog.rs
Expand Up @@ -84,7 +84,7 @@ impl CombinedLogger {

Box::new(CombinedLogger {
level: log_level,
logger: logger,
logger,
})
}
}
Expand Down
11 changes: 5 additions & 6 deletions 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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -163,15 +162,15 @@ 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;
}
}
_ => {}
}

return false;
false
}
4 changes: 2 additions & 2 deletions src/loggers/simplelog.rs
Expand Up @@ -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))
}

Expand All @@ -59,7 +59,7 @@ impl SimpleLogger {
pub fn new(log_level: LevelFilter, config: Config) -> Box<SimpleLogger> {
Box::new(SimpleLogger {
level: log_level,
config: config,
config,
output_lock: Mutex::new(()),
})
}
Expand Down
5 changes: 2 additions & 3 deletions src/loggers/termlog.rs
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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(())
}
Expand Down Expand Up @@ -133,7 +132,7 @@ impl TermLogger {

Box::new(TermLogger {
level: log_level,
config: config,
config,
streams: Mutex::new(streams),
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/loggers/testlog.rs
Expand Up @@ -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))
}

Expand Down
4 changes: 2 additions & 2 deletions src/loggers/writelog.rs
Expand Up @@ -36,7 +36,7 @@ impl<W: Write + Send + 'static> WriteLogger<W> {
/// # }
/// ```
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))
}

Expand All @@ -59,7 +59,7 @@ impl<W: Write + Send + 'static> WriteLogger<W> {
pub fn new(log_level: LevelFilter, config: Config, writable: W) -> Box<WriteLogger<W>> {
Box::new(WriteLogger {
level: log_level,
config: config,
config,
writable: Mutex::new(writable),
})
}
Expand Down

0 comments on commit e741dd8

Please sign in to comment.