From cbdb017fe2b4045d4bf0c554223f827888a44dd4 Mon Sep 17 00:00:00 2001 From: lkoester Date: Thu, 25 Apr 2024 14:38:51 +0200 Subject: [PATCH] added logging directories with date --- Cargo.lock | 1 + Cargo.toml | 1 + src/logger.rs | 8 ++++++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a0d88f0..423e078 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -613,6 +613,7 @@ dependencies = [ "log", "mio", "num_enum", + "once_cell", "satrs", "satrs-mib", "serde", diff --git a/Cargo.toml b/Cargo.toml index 70493df..f0093c1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,7 @@ serde_json = "1" mio = "0.8" homedir = "0.2" socket2 = "0.5" +once_cell = "1.19" [dependencies.satrs] version = "0.2.0-rc.5" diff --git a/src/logger.rs b/src/logger.rs index c186deb..fe5914b 100644 --- a/src/logger.rs +++ b/src/logger.rs @@ -1,13 +1,17 @@ use std::path::{Path, PathBuf}; - +use once_cell::sync::OnceCell; use ops_sat_rs::config::LOG_FOLDER; +pub static LOGFILE_PATH: OnceCell = OnceCell::new(); + pub fn setup_logger() -> Result<(), fern::InitError> { if !Path::new(LOG_FOLDER).exists() && std::fs::create_dir_all(LOG_FOLDER).is_err() { eprintln!("Failed to create log folder '{}'", LOG_FOLDER); } let mut path_buf = PathBuf::from(LOG_FOLDER); - path_buf.push("output.log"); + path_buf.push(format!("output_{}.log", humantime::format_rfc3339_seconds(std::time::SystemTime::now()).to_string()).replace(":", "_")); + println!("Creating logfile {:?}", path_buf); + LOGFILE_PATH.set(path_buf.clone()).expect("Error setting global logfile path"); fern::Dispatch::new() .format(move |out, message, record| { out.finish(format_args!(