From 9098ee43607340769d1dddf88522cc1bf9b1788f Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Fri, 12 Mar 2010 06:01:21 +0000 Subject: [PATCH] Issue #8117: logging: Improved algorithm for computing initial rollover time. --- Lib/logging/handlers.py | 8 ++++++-- Misc/NEWS | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py index 8f890bc9fe8..30af6f29052 100644 --- a/Lib/logging/handlers.py +++ b/Lib/logging/handlers.py @@ -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): """ diff --git a/Misc/NEWS b/Misc/NEWS index 59a7bc30977..c74eff18a27 100644 --- 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.