refactor(log): apply more clippy findings
cargo devel CI / cargo CI (push) Failing after 1m44s Details

This commit is contained in:
Christoph J. Scherr 2024-07-09 18:25:50 +02:00
parent 73f935d9b2
commit b2bf00db46
3 changed files with 28 additions and 14 deletions

View File

@ -23,9 +23,16 @@ struct Cli {
fn main() { fn main() {
let cli = Cli::parse(); let cli = Cli::parse();
let _logger = Logger::builder() let _logger = {
.max_level(cli.verbosity.level()) let mut this = {
.show_time(false) let mut this = Logger::builder();
let max_level = cli.verbosity.level();
this.max_level = max_level;
this
};
this.show_time = false;
this
}
.build(); .build();
debug!("logger initialized with level: {}", cli.verbosity.level()); debug!("logger initialized with level: {}", cli.verbosity.level());

View File

@ -31,9 +31,16 @@ enum ReplCommand {
fn main() -> anyhow::Result<()> { fn main() -> anyhow::Result<()> {
// You would normally make a proper cli interface with clap before entering the repl. This is // You would normally make a proper cli interface with clap before entering the repl. This is
// omitted here for brevity // omitted here for brevity
let _logger = Logger::builder() let _logger = {
.show_time(false) let mut this = {
.max_level(Level::INFO) let mut this = Logger::builder();
this.show_time = false;
this
};
let max_level = Level::INFO;
this.max_level = max_level;
this
}
.build()?; .build()?;
// the compiler can infer that we want to use the ReplCommand enum. // the compiler can infer that we want to use the ReplCommand enum.

View File

@ -378,35 +378,35 @@ impl Logger {
where where
T: fmt::Display, T: fmt::Display,
{ {
error!("{}", printable) error!("{}", printable);
} }
/// ## logging at [`Level::WARN`] /// ## logging at [`Level::WARN`]
pub fn warn<T>(&self, printable: T) pub fn warn<T>(&self, printable: T)
where where
T: fmt::Display, T: fmt::Display,
{ {
warn!("{}", printable) warn!("{}", printable);
} }
/// ## logging at [`Level::INFO`] /// ## logging at [`Level::INFO`]
pub fn info<T>(&self, printable: T) pub fn info<T>(&self, printable: T)
where where
T: fmt::Display, T: fmt::Display,
{ {
info!("{}", printable) info!("{}", printable);
} }
/// ## logging at [`Level::DEBUG`] /// ## logging at [`Level::DEBUG`]
pub fn debug<T>(&self, printable: T) pub fn debug<T>(&self, printable: T)
where where
T: fmt::Display, T: fmt::Display,
{ {
debug!("{}", printable) debug!("{}", printable);
} }
/// ## logging at [`Level::TRACE`] /// ## logging at [`Level::TRACE`]
pub fn trace<T>(&self, printable: T) pub fn trace<T>(&self, printable: T)
where where
T: fmt::Display, T: fmt::Display,
{ {
trace!("{}", printable) trace!("{}", printable);
} }
} }
@ -430,6 +430,6 @@ impl Default for Logger {
} }
fn new_file_appender(log_dir: PathBuf) -> NonBlocking { 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 tracing_appender::non_blocking(file_appender).0
} }