fix clippy warnigns
This commit is contained in:
+6
-9
@@ -1,4 +1,3 @@
|
||||
// src/error_logger.rs
|
||||
#![warn(clippy::all, clippy::pedantic)]
|
||||
|
||||
use chrono::{DateTime, Utc};
|
||||
@@ -6,7 +5,7 @@ use serde::Serialize;
|
||||
use std::fs::OpenOptions;
|
||||
use std::io::{BufWriter, Write};
|
||||
use std::path::Path;
|
||||
use std::sync::Mutex;
|
||||
use std::sync::{LazyLock, Mutex};
|
||||
use url::Url;
|
||||
|
||||
#[derive(Serialize)]
|
||||
@@ -19,9 +18,8 @@ pub struct ErrorEntry {
|
||||
pub status_code: Option<u16>,
|
||||
}
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
static ref LOG_WRITER: Mutex<Option<BufWriter<std::fs::File>>> = Mutex::new(None);
|
||||
}
|
||||
static LOG_WRITER: LazyLock<Mutex<Option<BufWriter<std::fs::File>>>> =
|
||||
LazyLock::new(|| Mutex::new(None));
|
||||
|
||||
pub fn log_error(
|
||||
log_path: &Path,
|
||||
@@ -41,18 +39,17 @@ pub fn log_error(
|
||||
let line = match serde_json::to_string(&entry) {
|
||||
Ok(json) => json + "\n",
|
||||
Err(e) => {
|
||||
log::error!("Failed to serialize error entry: {}", e);
|
||||
log::error!("Failed to serialize error entry: {e}");
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
// Buffered writer approach
|
||||
{
|
||||
let mut guard = LOG_WRITER.lock().unwrap();
|
||||
match guard.as_mut() {
|
||||
Some(writer) => {
|
||||
if let Err(e) = writer.write_all(line.as_bytes()) {
|
||||
log::error!("Failed to write error log: {}", e);
|
||||
log::error!("Failed to write error log: {e}");
|
||||
}
|
||||
}
|
||||
None => {
|
||||
@@ -68,5 +65,5 @@ pub fn log_error(
|
||||
}
|
||||
}
|
||||
|
||||
log::info!("LOGGED ERROR [{}]: {}", error_type, message);
|
||||
log::info!("LOGGED ERROR [{error_type}]: {message}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user