diff options
author | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2009-01-21 00:19:28 (GMT) |
---|---|---|
committer | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2009-01-21 00:19:28 (GMT) |
commit | 6268cbc77190cf6b4112a272f2870d5361903605 (patch) | |
tree | 3df927837dabe232be5d6264e96fd0036412c04f /Lib/logging/handlers.py | |
parent | b14043c1ec5e8eb25e2e728be64621458891eab3 (diff) | |
download | cpython-6268cbc77190cf6b4112a272f2870d5361903605.zip cpython-6268cbc77190cf6b4112a272f2870d5361903605.tar.gz cpython-6268cbc77190cf6b4112a272f2870d5361903605.tar.bz2 |
Issue 5013: Fixed bug in FileHandler when delay was set - added fix for RotatingFileHandler and changed header comment slightly.
Diffstat (limited to 'Lib/logging/handlers.py')
-rw-r--r-- | Lib/logging/handlers.py | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py index 5930f49..d9acb87 100644 --- a/Lib/logging/handlers.py +++ b/Lib/logging/handlers.py @@ -19,9 +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. -Copyright (C) 2001-2008 Vinay Sajip. All Rights Reserved. +Copyright (C) 2001-2009 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, os, pickle, struct, time, re @@ -112,8 +112,8 @@ class RotatingFileHandler(BaseRotatingHandler): """ Do a rollover, as described in __init__(). """ - - self.stream.close() + if self.stream: + self.stream.close() if self.backupCount > 0: for i in range(self.backupCount - 1, 0, -1): sfn = "%s.%d" % (self.baseFilename, i) @@ -138,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 @@ -302,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: |