[Python-checkins] r73357 - in python/branches/release26-maint: Lib/logging/handlers.py Misc/NEWS
vinay.sajip
python-checkins at python.org
Thu Jun 11 12:01:04 CEST 2009
Author: vinay.sajip
Date: Thu Jun 11 12:01:04 2009
New Revision: 73357
Log:
Issue #5262: Fixed bug in next roll over time computation in TimedRotatingFileHandler.
Modified:
python/branches/release26-maint/Lib/logging/handlers.py
python/branches/release26-maint/Misc/NEWS
Modified: python/branches/release26-maint/Lib/logging/handlers.py
==============================================================================
--- python/branches/release26-maint/Lib/logging/handlers.py (original)
+++ python/branches/release26-maint/Lib/logging/handlers.py Thu Jun 11 12:01:04 2009
@@ -203,8 +203,15 @@
self.extMatch = re.compile(self.extMatch)
self.interval = self.interval * interval # multiply by units requested
- self.rolloverAt = currentTime + self.interval
+ self.rolloverAt = self.computeRollover(int(time.time()))
+ #print "Will rollover at %d, %d seconds from now" % (self.rolloverAt, self.rolloverAt - currentTime)
+
+ def computeRollover(self, currentTime):
+ """
+ Work out the rollover time based on the specified time.
+ """
+ result = currentTime + self.interval
# If we are rolling over at midnight or weekly, then the interval is already known.
# What we need to figure out is WHEN the next interval is. In other words,
# if you are rolling over at midnight, then your base interval is 1 day,
@@ -214,7 +221,7 @@
# the rest. Note that this code doesn't care about leap seconds. :)
if self.when == 'MIDNIGHT' or self.when.startswith('W'):
# This could be done with less code, but I wanted it to be clear
- if utc:
+ if self.utc:
t = time.gmtime(currentTime)
else:
t = time.localtime(currentTime)
@@ -224,7 +231,7 @@
# r is the number of seconds left between now and midnight
r = _MIDNIGHT - ((currentHour * 60 + currentMinute) * 60 +
currentSecond)
- self.rolloverAt = currentTime + r
+ result = currentTime + r
# If we are rolling over on a certain day, add in the number of days until
# the next rollover, but offset by 1 since we just calculated the time
# until the next day starts. There are three cases:
@@ -240,15 +247,15 @@
# The calculations described in 2) and 3) above need to have a day added.
# This is because the above time calculation takes us to midnight on this
# day, i.e. the start of the next day.
- if when.startswith('W'):
+ if self.when.startswith('W'):
day = t[6] # 0 is Monday
if day != self.dayOfWeek:
if day < self.dayOfWeek:
daysToWait = self.dayOfWeek - day
else:
daysToWait = 6 - day + self.dayOfWeek + 1
- newRolloverAt = self.rolloverAt + (daysToWait * (60 * 60 * 24))
- if not utc:
+ newRolloverAt = result + (daysToWait * (60 * 60 * 24))
+ if not self.utc:
dstNow = t[-1]
dstAtRollover = time.localtime(newRolloverAt)[-1]
if dstNow != dstAtRollover:
@@ -256,9 +263,8 @@
newRolloverAt = newRolloverAt - 3600
else: # DST bows out before next rollover, so we need to add an hour
newRolloverAt = newRolloverAt + 3600
- self.rolloverAt = newRolloverAt
-
- #print "Will rollover at %d, %d seconds from now" % (self.rolloverAt, self.rolloverAt - currentTime)
+ result = newRolloverAt
+ return result
def shouldRollover(self, record):
"""
@@ -327,8 +333,8 @@
#print "%s -> %s" % (self.baseFilename, dfn)
self.mode = 'w'
self.stream = self._open()
- newRolloverAt = self.rolloverAt + self.interval
currentTime = int(time.time())
+ newRolloverAt = self.computeRollover(currentTime)
while newRolloverAt <= currentTime:
newRolloverAt = newRolloverAt + self.interval
#If DST changes and midnight or weekly rollover, adjust for this.
Modified: python/branches/release26-maint/Misc/NEWS
==============================================================================
--- python/branches/release26-maint/Misc/NEWS (original)
+++ python/branches/release26-maint/Misc/NEWS Thu Jun 11 12:01:04 2009
@@ -56,6 +56,9 @@
Library
-------
+- Issue #5262: Fixed bug in next rollover time computation in
+ TimedRotatingFileHandler.
+
- Issue #6121: pydoc now ignores leading and trailing spaces in the
argument to the 'help' function.
@@ -240,7 +243,7 @@
in Makefiles. This prevents compile errors when using syntax like:
`LDFLAGS='-rpath=\$$LIB:/some/other/path'`. Patch by Floris Bruynooghe.
-- Issue #6062: In distutils, fixed the package option of build_ext. Feedback
+- Issue #6062: In distutils, fixed the package option of build_ext. Feedback
and tests on pywin32 by Tim Golden.
- Issue #1309567: Fix linecache behavior of stripping subdirectories when
More information about the Python-checkins
mailing list