summaryrefslogtreecommitdiffstats
path: root/Lib/logging
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2009-06-11 10:11:47 (GMT)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>2009-06-11 10:11:47 (GMT)
commitaffbd871e3964b5101bd8756a5510ac68e291833 (patch)
treef8710c1c53b69b3d28041d3fc60311f33dbb25fe /Lib/logging
parente653a7d6af9d2e11191593df6c3796cba3cd529f (diff)
downloadcpython-affbd871e3964b5101bd8756a5510ac68e291833.zip
cpython-affbd871e3964b5101bd8756a5510ac68e291833.tar.gz
cpython-affbd871e3964b5101bd8756a5510ac68e291833.tar.bz2
Issue #5262: Fixed bug in next roll over time computation in TimedRotatingFileHandler.
Diffstat (limited to 'Lib/logging')
-rw-r--r--Lib/logging/handlers.py25
1 files changed, 14 insertions, 11 deletions
diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py
index 296237b..31352ad 100644
--- a/Lib/logging/handlers.py
+++ b/Lib/logging/handlers.py
@@ -172,7 +172,6 @@ class TimedRotatingFileHandler(BaseRotatingHandler):
#
# Case of the 'when' specifier is not important; lower or upper case
# will work.
- currentTime = int(time.time())
if self.when == 'S':
self.interval = 1 # one second
self.suffix = "%Y-%m-%d_%H-%M-%S"
@@ -203,8 +202,13 @@ class TimedRotatingFileHandler(BaseRotatingHandler):
self.extMatch = re.compile(self.extMatch, re.ASCII)
self.interval = self.interval * interval # multiply by units requested
- self.rolloverAt = currentTime + self.interval
+ self.rolloverAt = self.computeRollover(int(time.time()))
+ 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 +218,7 @@ class TimedRotatingFileHandler(BaseRotatingHandler):
# 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 +228,7 @@ class TimedRotatingFileHandler(BaseRotatingHandler):
# 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 +244,15 @@ class TimedRotatingFileHandler(BaseRotatingHandler):
# 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 +260,8 @@ class TimedRotatingFileHandler(BaseRotatingHandler):
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 +330,8 @@ class TimedRotatingFileHandler(BaseRotatingHandler):
#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.