From 6983a0541f54bca918c5622fb6b0ef073bcbf753 Mon Sep 17 00:00:00 2001 From: Andrew Hutchings Date: Tue, 19 Nov 2013 15:53:42 +0000 Subject: [PATCH] [LOGGING]: Fix multi-rollover When there is a long difference between the last time a log was opened and now there is a multi-rotate scenario which leaves the log files in a bit of a mess. This is typically seen on a worker that is spun up from an image. This stops the multi-rotate scenario from happening in Python's on log handler so should work for us. Change-Id: I5b07d52965e497adf229acef9e5a040e50729849 --- libra/common/log.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libra/common/log.py b/libra/common/log.py index 48d26951..871c43de 100644 --- a/libra/common/log.py +++ b/libra/common/log.py @@ -85,7 +85,9 @@ class CompressedTimedRotatingFileHandler( self.stream = codecs.open(self.baseFilename, 'w', self.encoding) else: self.stream = open(self.baseFilename, 'w') - self.rolloverAt = self.rolloverAt + self.interval + currentTime = int(time.time()) + while self.rolloverAt <= currentTime: + self.rolloverAt = self.rolloverAt + self.interval zfile = '{0}.gz'.format(tfn) if os.path.exists(zfile): os.remove(zfile)