From 9e567ae760664d11769092f83bc432b8fcdcf258 Mon Sep 17 00:00:00 2001 From: icsboyx Date: Mon, 12 Jan 2026 16:28:09 +0100 Subject: [PATCH] fix: update log file handling to include timestamp in renamed log files --- src/api.rs | 3 ++- src/main.rs | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/api.rs b/src/api.rs index b53fe08..27103e3 100644 --- a/src/api.rs +++ b/src/api.rs @@ -5,6 +5,7 @@ use serde::Deserialize; use serde_json::json; use crate::{ + LOG_FILE_NAME, data_mgt::{Asset, AssetTracker}, logs::{LogEvent, LogEventType, log_event}, }; @@ -100,7 +101,7 @@ async fn api_stats(assets: web::Data) -> Result = Vec::new(); let mut request_count: usize = 0; - let log_path = format!("{}access.log", LOG_DIR); + let log_path = format!("{}{}", LOG_DIR, LOG_FILE_NAME); if let Ok(content) = fs::read_to_string(&log_path) { for line in content.lines() { if let Ok(entry) = serde_json::from_str::(line) { diff --git a/src/main.rs b/src/main.rs index 0f084f2..ce46eec 100644 --- a/src/main.rs +++ b/src/main.rs @@ -89,7 +89,9 @@ async fn catch_all(req: HttpRequest, _payload: Option>) -> acti #[actix_web::main] async fn main() -> std::io::Result<()> { let _ = fs::create_dir_all(LOG_DIR); - let _ = fs::remove_file(format!("{}{}", LOG_DIR, LOG_FILE_NAME)); + let log_file_path = format!("{}{}", LOG_DIR, LOG_FILE_NAME); + let time_tag = chrono::Local::now().format("%Y_%m_%d"); + let _ = fs::rename(log_file_path, format!("{}_{}", time_tag, &LOG_FILE_NAME)); let assets = data_mgt::AssetTracker::new();