summaryrefslogtreecommitdiff
path: root/Lib/logging
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2009-06-11 09:23:41 +0000
committerVinay Sajip <vinay_sajip@yahoo.co.uk>2009-06-11 09:23:41 +0000
commit083cb962f3616b653368676923d150aa5f6fa5bd (patch)
tree3e26e82411b7c679f58e6a99aebd9311c2e4dbf5 /Lib/logging
parentc950b86f7f858b0d79d61a6303795b78448362dc (diff)
downloadcpython-083cb962f3616b653368676923d150aa5f6fa5bd.tar.gz
Issue #5262: Fixed bug in next roll over time computation in TimedRotatingFileHandler.
Diffstat (limited to 'Lib/logging')
-rw-r--r--Lib/logging/handlers.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py
index 6b21bed135..80bc291570 100644
--- a/Lib/logging/handlers.py
+++ b/Lib/logging/handlers.py
@@ -204,7 +204,13 @@ class TimedRotatingFileHandler(BaseRotatingHandler):
self.extMatch = re.compile(self.extMatch)
self.interval = self.interval * interval # multiply by units requested
self.rolloverAt = 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.
+ self.adjustRollover(currentTime)
+
+ #print "Will rollover at %d, %d seconds from now" % (self.rolloverAt, self.rolloverAt - currentTime)
+ def adjustRollover(self, currentTime):
# 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 +220,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)
@@ -240,7 +246,7 @@ 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:
@@ -248,7 +254,7 @@ class TimedRotatingFileHandler(BaseRotatingHandler):
else:
daysToWait = 6 - day + self.dayOfWeek + 1
newRolloverAt = self.rolloverAt + (daysToWait * (60 * 60 * 24))
- if not utc:
+ if not self.utc:
dstNow = t[-1]
dstAtRollover = time.localtime(newRolloverAt)[-1]
if dstNow != dstAtRollover:
@@ -258,8 +264,6 @@ class TimedRotatingFileHandler(BaseRotatingHandler):
newRolloverAt = newRolloverAt + 3600
self.rolloverAt = newRolloverAt
- #print "Will rollover at %d, %d seconds from now" % (self.rolloverAt, self.rolloverAt - currentTime)
-
def shouldRollover(self, record):
"""
Determine if rollover should occur.
@@ -341,6 +345,7 @@ class TimedRotatingFileHandler(BaseRotatingHandler):
else: # DST bows out before next rollover, so we need to add an hour
newRolloverAt = newRolloverAt + 3600
self.rolloverAt = newRolloverAt
+ self.adjustRollover(time.time())
class WatchedFileHandler(logging.FileHandler):
"""