classification
Title: Specifying the time a TimedRotatingFileHandler rotates
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: vinay.sajip Nosy List: eric.araujo, python-dev, ronaldoussoren, tshepang, vinay.sajip
Priority: normal Keywords: patch

Created on 2010-08-10 11:57 by ronaldoussoren, last changed 2013-04-12 16:04 by python-dev. This issue is now closed.

Files
File name Uploaded Description Edit
issue9556.txt ronaldoussoren, 2012-10-23 10:09 review
updated-patch.diff vinay.sajip, 2012-10-23 21:43 Added weekly test, docs to Ronald's patch review
post-comments.diff vinay.sajip, 2012-10-24 12:55 Taking Ronald's comments into account review
Repositories containing patches
http://hg.python.org/sandbox/vsajip#fix9556
Messages (7)
msg113527 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2010-08-10 11:57
The logging module contains a TimedRotatingFileHandler that automaticly rotates the logfile after a specified interval.

This class misses an important feature: it is not possible to specify at what time the file should be rotated, unless that time is midnight.

My usecase: one of our customers works night shifts which means that rotating logfiles at midnight means that files get rotated halfway through a shift instead of at the end of one.

We'd like to be able to specify that logfiles get rotated at a specific time (such as 7:00AM).
msg113565 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-08-10 22:21
Adding the logging maintainer to nosy. (BTW Vinay, Misc/maintainers.rst says your roundup name is “vsajip”)
msg114693 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2010-08-22 18:47
One way of implementing this is to use an additional optional "atTime" parameter which is a datetime.time instance, defaulting to None; a specified value would only be used if a 'when' value of 'D' or 'MIDNIGHT' were specified. In that case, computeRollover would be called with the specified time instead of the current time.

Would that meet your requirements?
msg173587 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2012-10-23 10:09
An 'atTime' argument would work. I'm currently using a subclass of BaseRotatingHandler that implements just the 'MIDNIGHT' option of TimedRotatingFileHandler  with a rotation hour argument.

The attached patch is a first attempt at implementing the 'atTime' option, it is currently lacking documentation and tests for the 'WEEKLY' value for 'when'.
msg173639 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2012-10-23 21:42
Thanks for the patch. I've added the weekly test and the documentation update, can you take a look?
msg173678 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2012-10-24 12:59
Thanks for the comments on Rietveld - patch updated.
msg186648 - (view) Author: Roundup Robot (python-dev) Date: 2013-04-12 16:04
New changeset eead4be1bdd9 by Vinay Sajip in branch 'default':
Closed #9556: Allowed specifying a time-of-day for a TimedRotatingFileHandler to rotate.
http://hg.python.org/cpython/rev/eead4be1bdd9
History
Date User Action Args
2013-04-12 16:04:35python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg186648

resolution: fixed
stage: patch review -> resolved
2013-03-07 10:46:55tshepangsetnosy: + tshepang
2012-10-24 12:59:07vinay.sajipsetmessages: + msg173678
2012-10-24 12:55:58vinay.sajipsetfiles: + post-comments.diff
2012-10-23 21:46:05vinay.sajipsetstage: needs patch -> patch review
2012-10-23 21:43:13vinay.sajipsetfiles: + updated-patch.diff
keywords: + patch
2012-10-23 21:42:51vinay.sajipsethgrepos: + hgrepo156
messages: + msg173639
2012-10-23 10:09:44ronaldoussorensetfiles: + issue9556.txt
status: pending -> open
messages: + msg173587

versions: + Python 3.4, - Python 3.2
2010-08-22 18:47:36vinay.sajipsetstatus: open -> pending
assignee: vinay.sajip
messages: + msg114693
2010-08-10 22:21:45eric.araujosetnosy: + vinay.sajip, eric.araujo
messages: + msg113565
2010-08-10 11:58:03ronaldoussorensettype: behavior -> enhancement
2010-08-10 11:57:35ronaldoussorencreate