From: Vinay Sajip Date: Tue, 20 Jan 2009 23:20:02 +0000 (+0000) Subject: Issue 5013: Fixed bug in FileHandler when delay was set - added fix for RotatingFileH... X-Git-Tag: v2.6.2c1~254 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=592f5fcb8d1d6f8c495e32ce0eae848c0e866dcd;p=python Issue 5013: Fixed bug in FileHandler when delay was set - added fix for RotatingFileHandler and changed header comment slightly. --- diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index 5ba9732eb8..eff0baec44 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -18,9 +18,6 @@ Logging package for Python. Based on PEP 282 and comments thereto in comp.lang.python, and influenced by Apache's log4j system. -Should work under Python versions >= 1.5.2, except that source line -information is not available unless 'sys._getframe()' is. - Copyright (C) 2001-2009 Vinay Sajip. All Rights Reserved. To use, simply 'import logging' and log away! diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py index 0d347fb79d..8c00a3d0be 100644 --- a/Lib/logging/handlers.py +++ b/Lib/logging/handlers.py @@ -19,12 +19,9 @@ Additional handlers for the logging package for Python. The core package is based on PEP 282 and comments thereto in comp.lang.python, and influenced by Apache's log4j system. -Should work under Python versions >= 1.5.2, except that source line -information is not available unless 'sys._getframe()' is. +Copyright (C) 2001-2009 Vinay Sajip. All Rights Reserved. -Copyright (C) 2001-2008 Vinay Sajip. All Rights Reserved. - -To use, simply 'import logging' and log away! +To use, simply 'import logging.handlers' and log away! """ import logging, socket, types, os, string, cPickle, struct, time, re @@ -141,6 +138,8 @@ class RotatingFileHandler(BaseRotatingHandler): Basically, see if the supplied record would cause the file to exceed the size limit we have. """ + if self.stream is None: # delay was set... + self.stream = self._open() if self.maxBytes > 0: # are we rolling over? msg = "%s\n" % self.format(record) self.stream.seek(0, 2) #due to non-posix-compliant Windows feature @@ -305,7 +304,8 @@ class TimedRotatingFileHandler(BaseRotatingHandler): then we have to get a list of matching filenames, sort them and remove the one with the oldest suffix. """ - self.stream.close() + if self.stream: + self.stream.close() # get the time that this sequence started at and make it a TimeTuple t = self.rolloverAt - self.interval if self.utc: