From b4c434e52feeae0ead2ac9157affdd249ff5bc50 Mon Sep 17 00:00:00 2001 From: Meinolf Block Date: Mon, 7 Oct 2024 15:11:51 +0200 Subject: [PATCH] Fix #178 --- CHANGELOG.md | 7 ++++++ Cargo.toml | 2 +- src/parameters/file_spec.rs | 25 +++++++++++++++++-- .../file_log_writer/state/list_and_cleanup.rs | 7 +++--- .../file_log_writer/state/timestamps.rs | 2 +- 5 files changed, 36 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fcc028f..7e00acb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.29.2] - 2024-10-07 + +Fix a regression ([issue #178](https://github.com/emabee/flexi_logger/issues/178)) +introduced with [0.29.1]. + +Fix error with rotation & append & explicit directory & Naming::Timestamps. + ## [0.29.1] - 2024-10-02 Fix [issue #176](https://github.com/emabee/flexi_logger/issues/176): diff --git a/Cargo.toml b/Cargo.toml index c8c37e1..09c3ed1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "flexi_logger" -version = "0.29.1" +version = "0.29.2" authors = ["emabee "] categories = ["development-tools::debugging"] description = """ diff --git a/src/parameters/file_spec.rs b/src/parameters/file_spec.rs index de49447..6a9bfe2 100644 --- a/src/parameters/file_spec.rs +++ b/src/parameters/file_spec.rs @@ -255,8 +255,10 @@ impl FileSpec { filename.push_str(timestamp); } if let Some(infix) = o_infix { - FileSpec::separate_with_underscore(&mut filename); - filename.push_str(infix); + if !infix.is_empty() { + FileSpec::separate_with_underscore(&mut filename); + filename.push_str(infix); + } }; if let Some(suffix) = &self.o_suffix { filename.push('.'); @@ -541,4 +543,23 @@ mod test { .as_pathbuf(None); assert!(path.file_name().is_none()); } + + #[test] + fn issue_178() { + let path = FileSpec::default() + .basename("BASENAME") + .suppress_timestamp() + .as_pathbuf(Some("")); + assert_eq!(path.file_name().unwrap().to_string_lossy(), "BASENAME.log"); + + let path = FileSpec::default() + .basename("BASENAME") + .discriminant("1") + .suppress_timestamp() + .as_pathbuf(Some("")); + assert_eq!( + path.file_name().unwrap().to_string_lossy(), + "BASENAME_1.log" + ); + } } diff --git a/src/writers/file_log_writer/state/list_and_cleanup.rs b/src/writers/file_log_writer/state/list_and_cleanup.rs index 26ce680..e45ac2e 100644 --- a/src/writers/file_log_writer/state/list_and_cleanup.rs +++ b/src/writers/file_log_writer/state/list_and_cleanup.rs @@ -45,8 +45,9 @@ pub(super) fn list_of_log_and_compressed_files(file_spec: &FileSpec) -> Vec Vec { - list_of_files(INFIX_PATTERN) +pub(super) fn list_of_infix_files(file_spec: &FileSpec) -> Vec { + let pattern = file_spec.as_glob_pattern(INFIX_PATTERN, file_spec.get_suffix().as_deref()); + list_of_files(&pattern) } fn list_of_files(pattern: &str) -> Vec { let mut log_files: Vec = glob::glob(pattern) @@ -60,7 +61,7 @@ fn list_of_files(pattern: &str) -> Vec { } pub(super) fn remove_or_compress_too_old_logfiles( - o_cleanup_thread_handle: &Option, + o_cleanup_thread_handle: Option<&CleanupThreadHandle>, cleanup_config: &Cleanup, file_spec: &FileSpec, writes_direct: bool, diff --git a/src/writers/file_log_writer/state/timestamps.rs b/src/writers/file_log_writer/state/timestamps.rs index dec61f8..29b3f5a 100644 --- a/src/writers/file_log_writer/state/timestamps.rs +++ b/src/writers/file_log_writer/state/timestamps.rs @@ -75,7 +75,7 @@ pub(super) fn latest_timestamp_file( Local::now() } else { // find all file paths that fit the pattern - list_of_infix_files() + list_of_infix_files(&config.file_spec) .into_iter() // retrieve the infix .map(|path| ts_infix_from_path(&path, &config.file_spec))