summaryrefslogtreecommitdiffstats
path: root/Lib/logging
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2008-01-24 12:37:08 (GMT)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>2008-01-24 12:37:08 (GMT)
commit97ef165a1d8dfebc7146ea038164dee52ca55e93 (patch)
tree086bfd1f4f266492137db8134d5aff5bad1c5b00 /Lib/logging
parent7b7ce7854c2e36d04adb42beec5f673071cf1fd4 (diff)
downloadcpython-97ef165a1d8dfebc7146ea038164dee52ca55e93.zip
cpython-97ef165a1d8dfebc7146ea038164dee52ca55e93.tar.gz
cpython-97ef165a1d8dfebc7146ea038164dee52ca55e93.tar.bz2
Added optional delay argument to FileHandler and subclasses.
Diffstat (limited to 'Lib/logging')
-rw-r--r--Lib/logging/__init__.py25
1 files changed, 20 insertions, 5 deletions
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index 2cb2bc9..157ce74 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -41,8 +41,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
@@ -763,7 +763,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.
"""
@@ -774,8 +774,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):
"""
@@ -798,6 +801,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
#---------------------------------------------------------------------------