From b2bf00db46c86f90f5776ef7ceb271170e149874 Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Tue, 9 Jul 2024 18:25:50 +0200 Subject: [PATCH] refactor(log): apply more clippy findings --- members/libpt-cli/examples/cli.rs | 15 +++++++++++---- members/libpt-cli/examples/repl.rs | 15 +++++++++++---- members/libpt-log/src/lib.rs | 12 ++++++------ 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/members/libpt-cli/examples/cli.rs b/members/libpt-cli/examples/cli.rs index 91fdcad..345a365 100644 --- a/members/libpt-cli/examples/cli.rs +++ b/members/libpt-cli/examples/cli.rs @@ -23,10 +23,17 @@ struct Cli { fn main() { let cli = Cli::parse(); - let _logger = Logger::builder() - .max_level(cli.verbosity.level()) - .show_time(false) - .build(); + let _logger = { + let mut this = { + let mut this = Logger::builder(); + let max_level = cli.verbosity.level(); + this.max_level = max_level; + this + }; + this.show_time = false; + this + } + .build(); debug!("logger initialized with level: {}", cli.verbosity.level()); diff --git a/members/libpt-cli/examples/repl.rs b/members/libpt-cli/examples/repl.rs index 28caf93..dc8c357 100644 --- a/members/libpt-cli/examples/repl.rs +++ b/members/libpt-cli/examples/repl.rs @@ -31,10 +31,17 @@ enum ReplCommand { fn main() -> anyhow::Result<()> { // You would normally make a proper cli interface with clap before entering the repl. This is // omitted here for brevity - let _logger = Logger::builder() - .show_time(false) - .max_level(Level::INFO) - .build()?; + let _logger = { + let mut this = { + let mut this = Logger::builder(); + this.show_time = false; + this + }; + let max_level = Level::INFO; + this.max_level = max_level; + this + } + .build()?; // the compiler can infer that we want to use the ReplCommand enum. let mut repl = DefaultRepl::::default(); diff --git a/members/libpt-log/src/lib.rs b/members/libpt-log/src/lib.rs index 0dabf7e..8a4a32f 100644 --- a/members/libpt-log/src/lib.rs +++ b/members/libpt-log/src/lib.rs @@ -378,35 +378,35 @@ impl Logger { where T: fmt::Display, { - error!("{}", printable) + error!("{}", printable); } /// ## logging at [`Level::WARN`] pub fn warn(&self, printable: T) where T: fmt::Display, { - warn!("{}", printable) + warn!("{}", printable); } /// ## logging at [`Level::INFO`] pub fn info(&self, printable: T) where T: fmt::Display, { - info!("{}", printable) + info!("{}", printable); } /// ## logging at [`Level::DEBUG`] pub fn debug(&self, printable: T) where T: fmt::Display, { - debug!("{}", printable) + debug!("{}", printable); } /// ## logging at [`Level::TRACE`] pub fn trace(&self, printable: T) where T: fmt::Display, { - trace!("{}", printable) + trace!("{}", printable); } } @@ -430,6 +430,6 @@ impl Default for Logger { } fn new_file_appender(log_dir: PathBuf) -> NonBlocking { - let file_appender = tracing_appender::rolling::daily(log_dir.clone(), "log"); + let file_appender = tracing_appender::rolling::daily(log_dir, "log"); tracing_appender::non_blocking(file_appender).0 }