Issue #5262: Fixed bug in next roll over time computation in TimedRotatingFileHandler.

This commit is contained in:
Vinay Sajip 2009-06-11 09:23:41 +00:00
parent c7498f5aab
commit 83da034c9a
2 changed files with 22 additions and 14 deletions

View File

@ -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):
"""

View File

@ -317,6 +317,9 @@ Core and Builtins
Library
-------
- Issue #5262: Fixed bug in next rollover time computation in
TimedRotatingFileHandler.
- Issue #6263: Fixed syntax error in distutils.cygwincompiler.
- Issue #5201: distutils.sysconfig.parse_makefile() now understands `$$`
@ -351,7 +354,7 @@ Library
- Issue #1424152: Fix for httplib, urllib2 to support SSL while working through
proxy. Original patch by Christopher Li, changes made by Senthil Kumaran.
- Issue #1983: Fix functions taking or returning a process identifier to use
the dedicated C type ``pid_t`` instead of a C ``int``. Some platforms have
a process identifier type wider than the standard C integer type.
@ -359,7 +362,7 @@ Library
- Issue #4066: smtplib.SMTP_SSL._get_socket now correctly returns the socket.
Patch by Farhan Ahmad, test by Marcin Bachry.
- 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 #6053: Fixed distutils tests on win32. patch by Hirokazu Yamamoto.
@ -367,7 +370,7 @@ Library
- Issue #6046: Fixed the library extension when distutils build_ext is used
inplace. Initial patch by Roumen Petrov.
- Issue #6041: Now distutils `sdist` and `register` commands use `check` as a
- Issue #6041: Now distutils `sdist` and `register` commands use `check` as a
subcommand.
- Issue #2116: Weak references and weak dictionaries now support copy()ing and
@ -517,8 +520,8 @@ Library
- unittest.assertNotEqual() now uses the inequality operator (!=) instead
of the equality operator.
- Issue #6001: Test discovery for unittest. Implemented in
- Issue #6001: Test discovery for unittest. Implemented in
unittest.TestLoader.discover and from the command line.
- Issue #5679: The methods unittest.TestCase.addCleanup and doCleanups were added.
@ -528,11 +531,11 @@ Library
- Issue #3379: unittest.main now takes an optional exit argument. If False main
doesn't call sys.exit allowing it to be used from the interactive interpreter.
- Issue #5995: unittest.main now takes an optional verbosity argument allowing
- Issue #5995: unittest.main now takes an optional verbosity argument allowing
test modules to be run with a higher than default verbosity.
- Issue #5995: A fix to allow you to run "python -m unittest test_module" or
- Issue #5995: A fix to allow you to run "python -m unittest test_module" or
"python -m unittest test_module.TestClass" from the command line.
- Issue #5728: unittest.TestResult has new startTestRun and stopTestRun methods;