emabee / flexi_logger

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

Add `LoggerHandle::{rotate, rotated_log_files}` methods #148

Closed newpavlov closed 1 year ago

newpavlov commented 1 year ago

Closes #147

emabee commented 1 year ago

Just wanted to start acting on this PR ... I didn't want to extend the LogWriter trait today, so I included only the core functionality in the upcoming patch version, but that was not supposed to mean it should not be done.

newpavlov commented 1 year ago

I think the trigger_rotation method added in the other commit should be sufficient for me. I only extended the trait because it looked like the most straightforward way to implement the functionality. And with the number of conflicts, I think it will be easier for you to start from scratch than change this PR.

It would be nice to get something like rotated_log_files later, but for now I can simply filter output of existing_log_files.

There is one minor issue with manual rotation, which I am not sure how to fix properly. When you rotate file and immediately get list of log files you sometimes get non-compressed log files, even though I use Cleanup::KeepCompressedFiles. To work around it in my code I added a simple waiting loop which stops when list of files does not contain any non-compressed rotated files.

emabee commented 1 year ago

I wanted to rework method existing_log_files so that it

Would that fit?

newpavlov commented 1 year ago

Yes, it would be great! Maybe it's also worth to add an option to trigger_rotation to wait for all triggered cleanups to finish? Or do it by default?

emabee commented 1 year ago

Good idea, thanks!