Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > TimedRotatingFileHandler() isn't rotating at midnight?

Reply
Thread Tools

TimedRotatingFileHandler() isn't rotating at midnight?

 
 
Chris Shenton
Guest
Posts: n/a
 
      02-01-2007
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)
 
Reply With Quote
 
 
 
 
Vinay Sajip
Guest
Posts: n/a
 
      02-09-2007
On 1 Feb, 05:32, Chris Shenton <(E-Mail Removed)> wrote:
> 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

 
Reply With Quote
 
 
 
 
Chris Shenton
Guest
Posts: n/a
 
      02-09-2007
"Vinay Sajip" <(E-Mail Removed)> writes:

> 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.
 
Reply With Quote
 
skip@pobox.com
Guest
Posts: n/a
 
      02-09-2007

>> Rotating should happen when the logging process creates the handler
>> before midnight and makes a logging call destined for that handler
>> after midnight.


Chris> Ah, then maybe I'm expecting the wrong thing. The python code is
Chris> invoked from cron every 10 minutes or so, it's not long-running.
Chris> Each time it opens the same log file. Sounds like this isn't
Chris> going to do what I want.

Right. Check out the logrotate facility on your system.

Skip
 
Reply With Quote
 
Vinay Sajip
Guest
Posts: n/a
 
      02-23-2007
On 9 Feb, 14:14, (E-Mail Removed) 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Rotating my shield harmonics MCSE 16 06-13-2005 03:23 PM
Rotating text in chat? Ray Java 2 05-16-2005 05:44 PM
rotating a bufferedimage e4_java Java 7 12-01-2004 03:08 AM
Rotating a Picturebox Charles A. Lackman ASP .Net 1 10-14-2004 09:39 AM
rotating an image mark | r HTML 4 07-02-2003 10:42 PM



Advertisments