TimedRotatingFileHandler() isn't rotating at midnight?

Discussion in 'Python' started by Chris Shenton, Feb 1, 2007.

  1. 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)
    Chris Shenton, Feb 1, 2007
    #1
    1. Advertising

  2. Chris Shenton

    Vinay Sajip Guest

    On 1 Feb, 05:32, Chris Shenton <> 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
    Vinay Sajip, Feb 9, 2007
    #2
    1. Advertising

  3. "Vinay Sajip" <> 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.
    Chris Shenton, Feb 9, 2007
    #3
  4. Chris Shenton

    Guest


    >> 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
    , Feb 9, 2007
    #4
  5. Chris Shenton

    Vinay Sajip Guest

    On 9 Feb, 14:14, 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
    Vinay Sajip, Feb 23, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jordan Richard

    Remove Object From Cache at Midnight

    Jordan Richard, Apr 30, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    1,124
    Jordan Richard
    Apr 30, 2005
  2. Gabriel Genellina

    Re: Problem with TimedRotatingFileHandler

    Gabriel Genellina, Jun 11, 2008, in forum: Python
    Replies:
    0
    Views:
    459
    Gabriel Genellina
    Jun 11, 2008
  3. Lokesh
    Replies:
    5
    Views:
    1,364
    Vinay Sajip
    Aug 11, 2009
  4. Dave Angel
    Replies:
    0
    Views:
    216
    Dave Angel
    Oct 24, 2012
  5. Vinay Sajip
    Replies:
    0
    Views:
    226
    Vinay Sajip
    Oct 24, 2012
Loading...

Share This Page