chore: fix lines

This commit is contained in:
Jesús Pérex 2025-05-27 01:02:00 +01:00
parent 238b2a13e5
commit 5d5ae2d759

View File

@ -1,11 +1,11 @@
use crate::error::{LogError, Result};
use chrono::Local;
use log::{LevelFilter, Log, Metadata, Record};
use log::{LevelFilter, Log, Record, Metadata};
use std::fs::OpenOptions;
use std::io::{self, Write};
use std::path::PathBuf;
use chrono::Local;
use std::sync::{Mutex, Arc};
use std::sync::OnceLock;
use std::sync::{Arc, Mutex};
use crate::error::{LogError, Result};
/// Configuration for logging setup
#[derive(Debug, Clone, PartialEq)]
@ -85,8 +85,7 @@ impl SimpleLogger {
.lock()
.map_err(|e| LogError::LockPoisoned(e.to_string()).into())
.and_then(|mut writer| {
writer
.write_all(message.as_bytes())
writer.write_all(message.as_bytes())
.and_then(|_| writer.flush())
.map_err(|e| LogError::Io(e).into())
})
@ -95,9 +94,7 @@ impl SimpleLogger {
impl Log for SimpleLogger {
fn enabled(&self, metadata: &Metadata) -> bool {
self.get_level()
.map(|level| metadata.level() <= level)
.unwrap_or(false)
self.get_level().map(|level| metadata.level() <= level).unwrap_or(false)
}
fn log(&self, record: &Record) {
@ -118,8 +115,7 @@ impl Log for SimpleLogger {
}
fn flush(&self) {
if let Err(e) = self
.writer
if let Err(e) = self.writer
.lock()
.map_err(|e| LogError::LockPoisoned(e.to_string()))
.and_then(|mut w| w.flush().map_err(LogError::Io))
@ -163,8 +159,7 @@ pub fn init_logging(config: LogConfig) -> Result<()> {
&file,
"=== Log started at {} ===",
Local::now().format("%Y-%m-%d %H:%M:%S")
)
.map_err(LogError::Io)?;
).map_err(LogError::Io)?;
}
Some(file)
} else {
@ -174,10 +169,9 @@ pub fn init_logging(config: LogConfig) -> Result<()> {
let level = LEVEL
.get_or_init(|| Arc::new(Mutex::new(config.log_level)))
.clone();
{
let mut lvl = level
.lock()
let mut lvl = level.lock()
.map_err(|e| LogError::LockPoisoned(e.to_string()))?;
*lvl = config.log_level;
}
@ -205,8 +199,7 @@ pub fn init_logging(config: LogConfig) -> Result<()> {
log::info!(
"Logging initialized (level: {}, output: {})",
config.log_level,
config
.log_file
config.log_file
.as_ref()
.map(|p| p.display().to_string())
.unwrap_or_else(|| "console".to_string())
@ -214,3 +207,4 @@ pub fn init_logging(config: LogConfig) -> Result<()> {
Ok(())
}