[Python-checkins] r60237 - python/trunk/Lib/logging/__init__.py

vinay.sajip python-checkins at python.org
Thu Jan 24 13:37:09 CET 2008


Author: vinay.sajip
Date: Thu Jan 24 13:37:08 2008
New Revision: 60237
Modified:
 python/trunk/Lib/logging/__init__.py
Log:
Added optional delay argument to FileHandler and subclasses.
Modified: python/trunk/Lib/logging/__init__.py
==============================================================================
--- python/trunk/Lib/logging/__init__.py	(original)
+++ python/trunk/Lib/logging/__init__.py	Thu Jan 24 13:37:08 2008
@@ -41,8 +41,8 @@
 
 __author__ = "Vinay Sajip <vinay_sajip at 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 @@
 """
 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 @@
 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 @@
 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
 #---------------------------------------------------------------------------


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /