async-worker / aiologger

Asynchronous logging for Python and asyncio
https://async-worker.github.io/aiologger/
MIT License
129 stars 13 forks source link

AsyncTimedRotatingFileHandler file delete issue #27

Open RokubanRKB opened 1 year ago

RokubanRKB commented 1 year ago

I am using time rotating file handler that roll over at midnight to create new log file every day.

With the backup_count set, I've noticed that when the backup files reached the setting value, the oldest file is not being deleted instead the latest rolled over file is been deleted.

https://github.com/async-worker/aiologger/blob/385a86301a5a1d6d592c9732b5324ca2796c61dc/aiologger/handlers/files.py#L393-L414

Upon checking the code in get_files_to_delete method.

The last part of the method returns the files that exceeds backup_count to be delete.

The reversed descending sort gives the wrong result and latest log file is being deleted.

Possible fix is remove reverse=True so the result list is in ascending sort.

Not sure if anyone else is having this issue.

My environment is Debian 11 with python 3.9.2 and aiologger 0.7.0 release.

edonavon commented 1 year ago

I confirm seeing the same issue and same solution as you suggested is working for me My environment is ubuntu 22, python 3.11.3, aiologger 0.7.0