fix: enhance log file rotation to include timestamp and improve error handling
This commit is contained in:
21
src/main.rs
21
src/main.rs
@@ -89,10 +89,25 @@ 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 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 log_filename = format!("{}{}", LOG_DIR, LOG_FILE_NAME);
|
||||
let log_filename_path = std::path::Path::new(&log_filename);
|
||||
|
||||
let time_tag = chrono::Local::now().format("%Y_%m_%d_%H_%M_%S");
|
||||
if log_filename_path.exists() {
|
||||
println!("File: {}, exists, rotating.", &log_filename_path.display());
|
||||
fs::rename(
|
||||
&log_filename_path,
|
||||
format!("{}{}_{}", LOG_DIR, time_tag, &LOG_FILE_NAME),
|
||||
)
|
||||
.unwrap_or_else(|e| {
|
||||
println!(
|
||||
"No existing log file {} to rotate. Error: {}",
|
||||
log_filename_path.to_string_lossy(),
|
||||
e
|
||||
)
|
||||
});
|
||||
println!("Rotated log file to: {}_{}", time_tag, &LOG_FILE_NAME);
|
||||
}
|
||||
let assets = data_mgt::AssetTracker::new();
|
||||
|
||||
println!("Starting server at http://{}:{}/", *BIND_ADDR, *BIND_PORT);
|
||||
|
||||
Reference in New Issue
Block a user