diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/logging/__init__.py | 25 | ||||
-rw-r--r-- | Lib/logging/handlers.py | 25 | ||||
-rw-r--r-- | Lib/test/test_descr.py | 2 | ||||
-rw-r--r-- | Lib/test/test_largefile.py | 2 |
4 files changed, 36 insertions, 18 deletions
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index 68fd10c..762ea43 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -38,8 +38,8 @@ except ImportError: __author__ = "Vinay Sajip <vinay_sajip@red-dove.com>" __status__ = "production" -__version__ = "0.5.0.4" -__date__ = "18 January 2008" +__version__ = "0.5.0.5" +__date__ = "24 January 2008" #--------------------------------------------------------------------------- # Miscellaneous module data @@ -760,7 +760,7 @@ class FileHandler(StreamHandler): """ A handler class which writes formatted logging records to disk files. """ - def __init__(self, filename, mode='a', encoding=None): + def __init__(self, filename, mode='a', encoding=None, delay=0): """ Open the specified file and use it as the stream for logging. """ @@ -771,8 +771,11 @@ class FileHandler(StreamHandler): self.baseFilename = os.path.abspath(filename) self.mode = mode self.encoding = encoding - stream = self._open() - StreamHandler.__init__(self, stream) + if delay: + self.stream = None + else: + stream = self._open() + StreamHandler.__init__(self, stream) def close(self): """ @@ -795,6 +798,18 @@ class FileHandler(StreamHandler): stream = codecs.open(self.baseFilename, self.mode, self.encoding) return stream + def emit(self, record): + """ + Emit a record. + + If the stream was not opened because 'delay' was specified in the + constructor, open it before calling the superclass's emit. + """ + if self.stream is None: + stream = self._open() + StreamHandler.__init__(self, stream) + StreamHandler.emit(self, record) + #--------------------------------------------------------------------------- # Manager classes and functions #--------------------------------------------------------------------------- diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py index 08bebbd..850e3bd 100644 --- a/Lib/logging/handlers.py +++ b/Lib/logging/handlers.py @@ -51,13 +51,13 @@ class BaseRotatingHandler(logging.FileHandler): Not meant to be instantiated directly. Instead, use RotatingFileHandler or TimedRotatingFileHandler. """ - def __init__(self, filename, mode, encoding=None): + def __init__(self, filename, mode, encoding=None, delay=0): """ Use the specified filename for streamed logging """ if codecs is None: encoding = None - logging.FileHandler.__init__(self, filename, mode, encoding) + logging.FileHandler.__init__(self, filename, mode, encoding, delay) self.mode = mode self.encoding = encoding @@ -82,7 +82,7 @@ class RotatingFileHandler(BaseRotatingHandler): Handler for logging to a set of files, which switches from one file to the next when the current file reaches a certain size. """ - def __init__(self, filename, mode='a', maxBytes=0, backupCount=0, encoding=None): + def __init__(self, filename, mode='a', maxBytes=0, backupCount=0, encoding=None, delay=0): """ Open the specified file and use it as the stream for logging. @@ -105,7 +105,7 @@ class RotatingFileHandler(BaseRotatingHandler): """ if maxBytes > 0: mode = 'a' # doesn't make sense otherwise! - BaseRotatingHandler.__init__(self, filename, mode, encoding) + BaseRotatingHandler.__init__(self, filename, mode, encoding, delay) self.maxBytes = maxBytes self.backupCount = backupCount @@ -154,8 +154,8 @@ class TimedRotatingFileHandler(BaseRotatingHandler): If backupCount is > 0, when rollover is done, no more than backupCount files are kept - the oldest ones are deleted. """ - def __init__(self, filename, when='h', interval=1, backupCount=0, encoding=None): - BaseRotatingHandler.__init__(self, filename, 'a', encoding) + def __init__(self, filename, when='h', interval=1, backupCount=0, encoding=None, delay=0): + BaseRotatingHandler.__init__(self, filename, 'a', encoding, delay) self.when = when.upper() self.backupCount = backupCount # Calculate the real rollover interval, which is just the number of @@ -300,10 +300,13 @@ class WatchedFileHandler(logging.FileHandler): This handler is based on a suggestion and patch by Chad J. Schroeder. """ - def __init__(self, filename, mode='a', encoding=None): - logging.FileHandler.__init__(self, filename, mode, encoding) - stat = os.stat(self.baseFilename) - self.dev, self.ino = stat[ST_DEV], stat[ST_INO] + def __init__(self, filename, mode='a', encoding=None, delay=0): + logging.FileHandler.__init__(self, filename, mode, encoding, delay) + if not os.path.exists(self.baseFilename): + self.dev, self.ino = -1, -1 + else: + stat = os.stat(self.baseFilename) + self.dev, self.ino = stat[ST_DEV], stat[ST_INO] def emit(self, record): """ @@ -319,7 +322,7 @@ class WatchedFileHandler(logging.FileHandler): else: stat = os.stat(self.baseFilename) changed = (stat[ST_DEV] != self.dev) or (stat[ST_INO] != self.ino) - if changed: + if changed and self.stream is not None: self.stream.flush() self.stream.close() self.stream = self._open() diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index 7ef702b..028be3d 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -4249,7 +4249,7 @@ def test_borrowed_ref_4_segfault(): builtins.__import__ = orig_import def test_main(): - #XXXweakref_segfault() # Must be first, somehow + weakref_segfault() # Must be first, somehow wrapper_segfault() # NB This one is slow do_this_first() class_docstrings() diff --git a/Lib/test/test_largefile.py b/Lib/test/test_largefile.py index a54a833..6d2e27d 100644 --- a/Lib/test/test_largefile.py +++ b/Lib/test/test_largefile.py @@ -6,7 +6,7 @@ #---------------------------------------------------------------------- from test import test_support -import os, struct, stat, sys +import os, stat, sys try: import signal |