TimedRotatingFileHandler() isn't rotating at midnight?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chris Shenton

    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.handler s
    logging.getLogg er().setLevel(l ogging.DEBUG) # override default of WARNING

    logfile = logging.handler s.TimedRotating FileHandler(fil ename, 'midnight', 1, backupCount=14)
    logfile.setLeve l(logging.DEBUG )
    logfile.setForm atter(logging.F ormatter('%(asc time)s %(levelname)-8s %(module)s: %(message)s'))
    logging.getLogg er().addHandler (logfile)
  • Vinay Sajip

    #2
    Re: TimedRotatingFi leHandler() isn't rotating at midnight?

    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 TimedRotatingFi leHandler 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

    Comment

    • Chris Shenton

      #3
      Re: TimedRotatingFi leHandler() isn't rotating at midnight?

      "Vinay Sajip" <vinay_sajip@ya hoo.co.ukwrites :
      It might. I assume you have a long-running process which runs past
      midnight - that's the scenario that TimedRotatingFi leHandler 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.

      Comment

      • skip@pobox.com

        #4
        Re: TimedRotatingFi leHandler() isn't rotating at midnight?

        >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

        Comment

        • Vinay Sajip

          #5
          Re: TimedRotatingFi leHandler() isn't rotating at midnight?

          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 WatchedFileHand ler 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

          Comment

          Working...