fix: update log file handling to include timestamp in renamed log files
This commit is contained in:
@@ -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<AssetTracker>) -> Result<HttpResponse, acti
|
||||
let mut recent_activity: Vec<ActivityItem> = 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::<LogEvent>(line) {
|
||||
|
||||
@@ -89,7 +89,9 @@ async fn catch_all(req: HttpRequest, _payload: Option<web::Json<Value>>) -> 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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user