summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorqkzk <qu3nt1n@gmail.com>2023-09-22 14:49:24 +0200
committerqkzk <qu3nt1n@gmail.com>2023-09-22 14:49:24 +0200
commit7a1d26e9be8976cdf42714be8535d7e33fbfa887 (patch)
treead50841936475ad83ed148713a27629e3f175571
parentbb9e69acaa8d70283afda0504f2626f95abedfa1 (diff)
remove rolling log, use delete instead :( $ENV{HOME} is created every time the rolls procs...
-rw-r--r--config_files/fm/logging_config.yaml5
-rw-r--r--src/log.rs27
2 files changed, 28 insertions, 4 deletions
diff --git a/config_files/fm/logging_config.yaml b/config_files/fm/logging_config.yaml
index b8ddf21..aad9f10 100644
--- a/config_files/fm/logging_config.yaml
+++ b/config_files/fm/logging_config.yaml
@@ -9,10 +9,7 @@ appenders:
kind: size
limit: 50kb
roller:
- kind: fixed_window
- base: 1
- count: 10
- pattern: "$ENV{HOME}/.config/fm/log/fm{}.log"
+ kind: delete
action_logger:
kind: rolling_file
path: "$ENV{HOME}/.config/fm/log/action_logger.log"
diff --git a/src/log.rs b/src/log.rs
index b86eecf..3823307 100644
--- a/src/log.rs
+++ b/src/log.rs
@@ -6,6 +6,7 @@ use crate::constant_strings_paths::{ACTION_LOG_PATH, LOG_CONFIG_PATH};
use crate::utils::extract_lines;
const ONE_DAY_IN_SECONDS: i64 = 24 * 60 * 60;
+// static ENV_HOME: &str = "$ENV{HOME}";
/// Set the logs.
/// The configuration is read from a config file defined in `LOG_CONFIG_PATH`
@@ -17,9 +18,35 @@ pub fn set_loggers() -> Result<()> {
shellexpand::tilde(LOG_CONFIG_PATH).as_ref(),
Default::default(),
)?;
+ // clear_useless_env_home()?;
Ok(())
}
+/// Delete useless $ENV{HOME} folder created by log4rs.
+/// This folder is created when a log file is big enough to proc a rolling
+/// Since the pattern can't be resolved, it's not created in the config folder but where the app is started...
+/// See [github issue](https://github.com/estk/log4rs/issues/314)
+/// The function log its results and delete nothing.
+// fn clear_useless_env_home() -> Result<()> {
+// let p = std::path::Path::new(&ENV_HOME);
+// let cwd = std::env::current_dir();
+// log::info!(
+// "looking from {ENV_HOME} - {p} CWD {cwd}",
+// p = p.display(),
+// cwd = cwd?.display()
+// );
+// if p.exists() && std::fs::metadata(ENV_HOME)?.is_dir()
+// // && std::path::Path::new(ENV_HOME).read_dir()?.next().is_none()
+// {
+// let z = std::path::Path::new(ENV_HOME).read_dir()?.next();
+// log::info!("z {z:?}");
+//
+// // std::fs::remove_dir_all(ENV_HOME)?;
+// log::info!("Removed {ENV_HOME} empty directory from CWD");
+// }
+// Ok(())
+// }
+
/// Returns the last line of the log file.
pub fn read_log() -> Result<Vec<String>> {
let log_path = shellexpand::tilde(ACTION_LOG_PATH).to_string();