]> granicus.if.org Git - python/commitdiff
Issue #8117: logging: Improved algorithm for computing initial rollover time.
authorVinay Sajip <vinay_sajip@yahoo.co.uk>
Fri, 12 Mar 2010 06:01:21 +0000 (06:01 +0000)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>
Fri, 12 Mar 2010 06:01:21 +0000 (06:01 +0000)
Lib/logging/handlers.py
Misc/NEWS

index 8f890bc9fe8c1c63f606280da69bfd79e17ef50f..30af6f290521ddaa41205602e2de4dc4355ce2a5 100644 (file)
@@ -25,7 +25,7 @@ To use, simply 'import logging.handlers' and log away!
 """
 
 import logging, socket, os, cPickle, struct, time, re
-from stat import ST_DEV, ST_INO
+from stat import ST_DEV, ST_INO, ST_MTIME
 
 try:
     import codecs
@@ -208,7 +208,11 @@ class TimedRotatingFileHandler(BaseRotatingHandler):
 
         self.extMatch = re.compile(self.extMatch)
         self.interval = self.interval * interval # multiply by units requested
-        self.rolloverAt = self.computeRollover(int(time.time()))
+        if os.path.exists(filename):
+            t = os.stat(filename)[ST_MTIME]
+        else:
+            t = int(time.time())
+        self.rolloverAt = self.computeRollover(t)
 
     def computeRollover(self, currentTime):
         """
index 59a7bc30977ccc81d8bc0b9f245e6569e7437acc..c74eff18a2783f841f0b64a1a6ce054bd72e5679 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -24,6 +24,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #8117: logging: Improved algorithm for computing initial rollover time.
+
 - Issue #6472: The xml.etree package is updated to ElementTree 1.3.  The
   cElementTree module is updated too.