1

I use the logging.handlers.TimedRotatingFileHandler to rotate the access log in my django project. The setting of 'when' attribute is 'midnight', and the rotate works well most of the time, but sometimes it does not work as I want to, just like below:

-rw-rw-r-- 1 work work 5.5M Jun 28 23:59 sd.log.2014-06-28
-rw-rw-r-- 1 work work 5.1M Jun 27 23:59 sd.log.2014-06-27
-rw-rw-r-- 1 work work 5.2M Jun 26 23:59 sd.log.2014-06-26
-rw-rw-r-- 1 work work  146 Jun 26 00:00 sd.log.2014-06-25
-rw-rw-r-- 1 work work 5.1M Jun 24 23:59 sd.log.2014-06-24
-rw-rw-r-- 1 work work  123 Jun 24 00:00 sd.log.2014-06-23
-rw-rw-r-- 1 work work 5.2M Jun 22 23:59 sd.log.2014-06-22

Both the log of the 2014-06-23 and 2014-06-25 are rotated at 00:00 while others at 23:59, and the file size is abnormal, too.

P.S.: it writes to the log file any time when there is request call for my api.

So, what's the reason cause the problem and how to solve it, has anyone met the problem, hope for your help, thanks a lot.

1 Answer 1

1

You should check that your python process hasn't been interrupted. Originally TimedRotatingFileHandler was designed for longtime running processes. If your process was restarted many times during the day you would notice misbehaviours.

The explanation can be found at this thread.

Please keep in mind the fact that Django's runserver by default restarts python process if project files were updated.

Sign up to request clarification or add additional context in comments.

1 Comment

The deployment I use is nginx + uwsgi + django. I import the logging.handler.TimeRotatingFileHandler in one of my applications' views.When there is a request call for the api,the app will record the request info into the log file. But sometimes the rotated yesterday file is not right, the file size is so small and the modified time is different from the right ones. Is this a bug of TimeRotatingFileHandler, or what causes the problem and how solve it? Despire for your help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.