468,291 Members | 1,548 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,291 developers. It's quick & easy.

TimedRotatingFileHandler() isn't rotating at midnight?

I set this up 3 days ago and have not seen any of the logs I've
created this way being rotated. I expected them to rotate every
midnight. I'm calling the code that uses this logger many times, each
a separate run, if that matters.

Am I doing something stupid? I can't find anything on google and don't
see anything in the code that would prevent rotating.

Thanks.

import logging, logging.handlers
logging.getLogger().setLevel(logging.DEBUG) # override default of WARNING

logfile = logging.handlers.TimedRotatingFileHandler(filename , 'midnight', 1, backupCount=14)
logfile.setLevel(logging.DEBUG)
logfile.setFormatter(logging.Formatter('%(asctime) s %(levelname)-8s %(module)s: %(message)s'))
logging.getLogger().addHandler(logfile)
Feb 1 '07 #1
4 20110
On 1 Feb, 05:32, Chris Shenton <chris-list-pyt...@shenton.orgwrote:
I set this up 3 days ago and have not seen any of the logs I've
created this way being rotated. I expected them to rotate every
midnight. I'm calling the code that uses this logger many times, each
a separate run, if that matters.
It might. I assume you have a long-running process which runs past
midnight - that's the scenario that TimedRotatingFileHandler is meant
for. Can you post a complete minimal example which shows the problem?
Am I doing something stupid? I can't find anything on google and don't
see anything in the code that would prevent rotating.
Rotating should happen when the logging process creates the handler
before midnight and makes a logging call destined for that handler
after midnight.

Regards,

Vinay Sajip

Feb 9 '07 #2
"Vinay Sajip" <vi*********@yahoo.co.ukwrites:
It might. I assume you have a long-running process which runs past
midnight - that's the scenario that TimedRotatingFileHandler is meant
for. Can you post a complete minimal example which shows the problem?
Rotating should happen when the logging process creates the handler
before midnight and makes a logging call destined for that handler
after midnight.
Ah, then maybe I'm expecting the wrong thing. The python code is
invoked from cron every 10 minutes or so, it's not long-running.
Each time it opens the same log file. Sounds like this isn't going to
do what I want.

Thanks for the clarification.
Feb 9 '07 #3
>Rotating should happen when the logging process creates the handler
before midnight and makes a logging call destined for that handler
after midnight.
ChrisAh, then maybe I'm expecting the wrong thing. The python code is
Chrisinvoked from cron every 10 minutes or so, it's not long-running.
ChrisEach time it opens the same log file. Sounds like this isn't
Chrisgoing to do what I want.

Right. Check out the logrotate facility on your system.

Skip
Feb 9 '07 #4
On 9 Feb, 14:14, s...@pobox.com wrote:
Right. Check out the logrotate facility on your system.
This can be used together with the WatchedFileHandler recently checked
into SVN trunk - this (Unix/Linux-only) handler checks to see if the
dev or inode have changed, and if they have (because of rotation by
e.g. logrotate), reopens the file before writing to it.

Regards,

Vinay Sajip

Feb 23 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Ian Hubling | last post: by
1 post views Thread by Sandy Bremmer | last post: by
3 posts views Thread by avalence | last post: by
reply views Thread by Gabriel Genellina | last post: by
2 posts views Thread by =?Utf-8?B?YmlsbCB0aWU=?= | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.