quill icon indicating copy to clipboard operation
quill copied to clipboard

Max backup files not respected after application restart

Open RazielXYZ opened this issue 1 month ago • 1 comments

Describe the bug The max backup files setting does not seem to be respected after restarting the program. Old log files are not touched and Quill creates the set amount of files again, after which it starts to overwrite only the newly created ones. I'm not sure if this is a bug or intended, but it is not expected, at least for me.

To Reproduce

cfg.set_open_mode('w'); // (over)write
cfg.set_filename_append_option(quill::FilenameAppendOption::None);
cfg.set_rotation_max_file_size(1024 * 10); // 10 kB or some small value
cfg.set_rotation_naming_scheme(quill::RotatingFileSinkConfig::RotationNamingScheme::DateAndTime);
cfg.set_max_backup_files(2);

Expected Behaviour Older log files continue to be deleted/overwritten, and the amount of logs from this app/sink present in the directory where logs are being saved should never exceed max_backup_files plus 1 (for the current one)

Environment Details

  • Library Version: 10.2.0
  • Operating System: Behavior is the same across platforms (tested windows 11, ubuntu 24.04, debian testing)
  • Compiler: VS2022, VS2026, gcc15

Additional context If this is intended/desired behavior, is there any way to achieve the behavior I'm describing as expected instead?

RazielXYZ avatar Nov 21 '25 21:11 RazielXYZ

Hey, this is the current designed behavior for DateAndTime naming scheme

cfg.set_rotation_naming_scheme(quill::RotatingFileSinkConfig::RotationNamingScheme::DateAndTime);

The DateAndTime scheme creates unique timestamps for each rotation so there are no filename collisions between program runs. The current implementation assumes users want to preserve historical logs across restarts.

https://github.com/odygrd/quill/blob/24a4ee29f4ae95cb3fdc8113d8ac72e5992f4f39/include/quill/sinks/RotatingSink.h#L495

Workarounds:

  1. Use Index or Date naming scheme - these properly respect max_backup_files across restarts
  2. Implement a custom sink that extends RotatingFileSink and remove old DateAndTime files on startup

odygrd avatar Nov 22 '25 05:11 odygrd