Skip to content

Commit

Permalink
Fix LoggerHandle::existing_log_files for cases without rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
emabee committed Aug 21, 2024
1 parent f93e392 commit d11184b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
14 changes: 13 additions & 1 deletion src/writers/file_log_writer/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,14 @@ enum Inner {
Initial(Option<RotationConfig>, bool),
Active(Option<RotationState>, Box<dyn Write + Send>, PathBuf),
}
impl Inner {
fn uses_rotation(&self) -> bool {
match self {
Inner::Initial(o_r, _) => o_r.is_some(),
Inner::Active(o_r, _, _) => o_r.is_some(),
}
}
}
impl std::fmt::Debug for Inner {
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
match self {
Expand Down Expand Up @@ -514,7 +522,11 @@ impl State {
}

pub fn existing_log_files(&self, selector: &LogfileSelector) -> Vec<PathBuf> {
list_and_cleanup::existing_log_files(&self.config.file_spec, selector)
list_and_cleanup::existing_log_files(
&self.config.file_spec,
self.inner.uses_rotation(),
selector,
)
}

pub fn validate_logs(&mut self, expected: &[(&'static str, &'static str, &'static str)]) {
Expand Down
36 changes: 23 additions & 13 deletions src/writers/file_log_writer/state/list_and_cleanup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,39 @@ use std::{

const INFIX_PATTERN: &str = "_r[0-9]*";

pub(super) fn existing_log_files(file_spec: &FileSpec, selector: &LogfileSelector) -> Vec<PathBuf> {
pub(super) fn existing_log_files(
file_spec: &FileSpec,
use_rotation: bool,
selector: &LogfileSelector,
) -> Vec<PathBuf> {
let mut result = Vec::new();
if selector.with_plain_files {
let pattern = file_spec.as_glob_pattern(INFIX_PATTERN, file_spec.get_suffix().as_deref());
result.append(&mut list_of_files(&pattern));
}
if use_rotation {
if selector.with_plain_files {
let pattern =
file_spec.as_glob_pattern(INFIX_PATTERN, file_spec.get_suffix().as_deref());
result.append(&mut list_of_files(&pattern));
}

if selector.with_compressed_files {
let pattern = file_spec.as_glob_pattern(INFIX_PATTERN, Some("gz"));
result.append(&mut list_of_files(&pattern));
}
if selector.with_compressed_files {
let pattern = file_spec.as_glob_pattern(INFIX_PATTERN, Some("gz"));
result.append(&mut list_of_files(&pattern));
}

if selector.with_r_current {
let pattern =
file_spec.as_glob_pattern(super::CURRENT_INFIX, file_spec.get_suffix().as_deref());
result.append(&mut list_of_files(&pattern));
if selector.with_r_current {
let pattern =
file_spec.as_glob_pattern(super::CURRENT_INFIX, file_spec.get_suffix().as_deref());
result.append(&mut list_of_files(&pattern));
}
} else {
result.push(file_spec.as_pathbuf(None));
}
result
}

pub(super) fn list_of_log_and_compressed_files(file_spec: &FileSpec) -> Vec<PathBuf> {
existing_log_files(
file_spec,
true,
&LogfileSelector::default().with_compressed_files(),
)
}
Expand Down

0 comments on commit d11184b

Please sign in to comment.