This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Patch for Vinay Sajip's Python-logging package
Type: Stage:
Components: Library (Lib) Versions: Python 2.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: vinay.sajip Nosy List: jimjjewett, medavidson, vinay.sajip
Priority: normal Keywords: patch

Created on 2004-03-22 19:58 by medavidson, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
handlers.patch medavidson, 2004-03-22 19:58 Patch for handlers.py to add TimedRotatingFileHandler support.
Messages (4)
msg45620 - (view) Author: Mark E. Davidson (medavidson) Date: 2004-03-22 19:58
This is a patch for Vinay Sajip's Python-logging
package.  It adds the support for time-based log
rollovers.  Specifically, it adds a new handler called
TimedRotatingFIleHandler.  TimedRotatingFileHandler
works just like the existing RotatingFileHandler,
except that instead of rolling over when the log file
hits a certain size, it rolls over when a time-interval
has occurred.

You can have the log files rollover ever <n> seconds,
minutes, hours, days.  You can have log files rollover
at midnight.  Log files can also roll over on a day of
the week.

The name of the log file is customized to fit the
interval specified.  In other words, it's suffix is
changed to match the interval you asked for.  If you
asked for it to roll over every hour, then the log file
has a suffix with the year, month, day and hour, but if
you roll over on a certain minute, then the suffix also
has the minute.

I had an extended correspondence with Vinay about this
code as I was writing it, so he knows it's coming.

It's been mostly tested, but not every variation has
been exercised.  The rollovers at seconds, minutes,
hours have been exercised, as well as the midnight
rollover, but the not the day of week.  Additionally,
the backupCount variation of the
TimedRotatingFileHandler is somewhat simplistic and not
well tested.

This patch only affects handlers.py.  It does NOT patch
the graphical TkInter-based log configuration utility,
as I ran out of time to work on this and Vinay said he
might change the class layout.

msg45621 - (view) Author: Jim Jewett (jimjjewett) Date: 2004-03-25 16:07
Logged In: YES 
user_id=764593

(1)
I think the H in the suffixes need to be capitalized.

>>> time.strftime("%Y-%m-%d_%h-%M-%S", tt)
'2004-03-25_-53-07'
>>> time.strftime("%Y-%m-%d_%H-%M-%S", tt)
'2004-03-25_10-53-07'

(2)  
When globbing for old logfiles to delete, please make it more 
specfic.  For instance, all suffixes (for the next century) start 
with "20", so you could use 

    s = glob.glob(self.basFilename + ".20*")  

This will make it a bit less dangerous for someone to copy a 
file as basename.save when they want to save the info for 
debugging later.

(3)  
The midnight and weekly versions should recalculate the 
rolloverAt instead of adding interval.  This will keep them from 
getting out of synch if there is a maintenance window or 
daylight savings time change.
msg45622 - (view) Author: Mark E. Davidson (medavidson) Date: 2004-03-25 19:14
Logged In: YES 
user_id=877141

jimjjewitt is correct.  I will try to fix these three issues and upload a new 
patch in the next day or so.
msg45623 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2004-07-12 09:31
Logged In: YES 
user_id=308438

Patch applied in CVS.
History
Date User Action Args
2022-04-11 14:56:03adminsetgithub: 40063
2004-03-22 19:58:26medavidsoncreate