fix: update log file handling to include timestamp in renamed log files

This commit is contained in:
2026-01-12 16:28:09 +01:00
parent 0685de8ffa
commit 9e567ae760
2 changed files with 5 additions and 2 deletions

View File

@@ -5,6 +5,7 @@ use serde::Deserialize;
use serde_json::json; use serde_json::json;
use crate::{ use crate::{
LOG_FILE_NAME,
data_mgt::{Asset, AssetTracker}, data_mgt::{Asset, AssetTracker},
logs::{LogEvent, LogEventType, log_event}, logs::{LogEvent, LogEventType, log_event},
}; };
@@ -100,7 +101,7 @@ async fn api_stats(assets: web::Data<AssetTracker>) -> Result<HttpResponse, acti
let mut recent_activity: Vec<ActivityItem> = Vec::new(); let mut recent_activity: Vec<ActivityItem> = Vec::new();
let mut request_count: usize = 0; 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) { if let Ok(content) = fs::read_to_string(&log_path) {
for line in content.lines() { for line in content.lines() {
if let Ok(entry) = serde_json::from_str::<LogEvent>(line) { if let Ok(entry) = serde_json::from_str::<LogEvent>(line) {

View File

@@ -89,7 +89,9 @@ async fn catch_all(req: HttpRequest, _payload: Option<web::Json<Value>>) -> acti
#[actix_web::main] #[actix_web::main]
async fn main() -> std::io::Result<()> { async fn main() -> std::io::Result<()> {
let _ = fs::create_dir_all(LOG_DIR); 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(); let assets = data_mgt::AssetTracker::new();