FAQ
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)
logfile.setLevel(logging.DEBUG)
logfile.setFormatter(logging.Formatter('%(asctime)s %(levelname)-8s %(module)s: %(message)s'))
logging.getLogger().addHandler(logfile)

Search Discussions

  • Vinay Sajip at Feb 9, 2007 at 11:50 am

    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
  • Chris Shenton at Feb 9, 2007 at 2:07 pm

    "Vinay Sajip" <vinay_sajip at yahoo.co.uk> 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.
  • Skip at Feb 9, 2007 at 2:14 pm

    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
  • Vinay Sajip at Feb 23, 2007 at 11:15 am

    On 9 Feb, 14:14, s... at 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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedFeb 1, '07 at 5:32a
activeFeb 23, '07 at 11:15a
posts5
users4
websitepython.org

People

Translate

site design / logo © 2022 Grokbase