emabee / flexi_logger

A flexible logger for rust programs that can write to stderr, stdout, and/or to log files
Apache License 2.0
315 stars 55 forks source link

Old log files are not removed if rCURRENT doesn't overflow #38

Closed ghost closed 4 years ago

ghost commented 4 years ago

When a FileLogWriterState is created, it sometimes rotate_output_file_to_date but does not call remove_or_zip_too_old_logfiles. The latter is only called when an existing _rCURRENT overflows. Therefore when a downstream program is run repeatedly, but doesn't generate enough log messages to trigger mount_next_linewriter_if_necessary in a single run, old rCURRENT messages can accumulate indefinitely in the log directory.

emabee commented 4 years ago

Thanks for reporting, I'll check ASAP. May I ask for your Logger configuration (as far as relevant)?

ghost commented 4 years ago

Below is a configuration that replicates the issue:

Logger::with_str("info")
        .log_to_file()
        .directory("log_files")
        .rotate(
            Criterion::Size(8192),
            Naming::Timestamps,
            Cleanup::KeepLogFiles(3),
        )
        .start()
        .unwrap();

When only a small amount of log messages are generated in the lifetime of a program, the procedure to clean up previous log files is not triggered, so log files keep accumulating. When the clean-up procedure is triggered in any single run that generates enough log messages, the old log files are removed to comply with Cleanup::KeepLogFiles(u64).

emabee commented 4 years ago

Fixed with 0.14.6. Thanks for reporting!