EDIT:
Looks like other people are having a similar issue with TimedRotatingFileHandler
.
Why doesn't my TimedRotatingFileHandler rotate at midnight?
Apparently, the logs don't rotate unless there is some activity happening in the logs. Is there a way I can achieve the scheduled rotating functionality I want using the builtin Handlers without having to create a custom rotator?
ORIGINAL POST:
I'm using the TimedRotatingFileHandler
of Python's logging
module to rotate my logs regularly.
I've specified the configurations in logging.conf for my app's loggers and handlers as such:
[logger_worker]
level=DEBUG
propogate=0
qualname=worker
handlers=workerHandler
[handler_workerHandler]
class=handlers.TimedRotatingFileHandler
level=DEBUG
formatter=standardFormatter
args=("/var/log/app/worker.log","M",1,30,None,False,False)
- Note: for testing purposes I've configured the handler to rotate the logs on every minute, but ideally the logs will be rotated on a daily basis at midnight.
In my app, I am creating the logger like this:
logging.config.fileConfig("logging.conf")
log = logging.getLogger("worker")
log.debug('Hello world')
It is not working as I expected it to work:
- It is not rotating all the logs
- It is not rotating every minute as it is configured to do
Observe the ls -l
output of the log directory:
-rw-r--r-- 1 root root 0 Apr 19 18:22 dpv.log
-rw-r----- 1 root root 5092 Apr 20 11:47 emperor.log
-rw-r--r-- 1 root root 88939 Apr 20 11:47 uwsgi.log
-rw-r--r-- 1 root root 494 Apr 20 11:46 worker.log
-rw-r--r-- 1 root root 45906 Apr 20 02:08 worker.log.2016-04-20_02-08
-rw-r--r-- 1 root root 494 Apr 20 11:34 worker.log.2016-04-20_11-34
-rw-r--r-- 1 root root 494 Apr 20 11:36 worker.log.2016-04-20_11-36
-rw-r--r-- 1 root root 494 Apr 20 11:44 worker.log.2016-04-20_11-44
What am I doing wrong? Is it possible to rotate the logs on a scheduled term even when nothing is being written to the logs?