[Zope3-checkins] CVS: Zope/lib/python/ZConfig/components/logger -
loghandler.py:1.3
Fred L. Drake, Jr.
fred at zope.com
Thu Apr 22 16:20:42 EDT 2004
Update of /cvs-repository/Zope/lib/python/ZConfig/components/logger
In directory cvs.zope.org:/tmp/cvs-serv28349/lib/python/ZConfig/components/logger
Modified Files:
loghandler.py
Log Message:
cleanly separate the debug logging handler from the startup logging handler;
these must be controllable separately
=== Zope/lib/python/ZConfig/components/logger/loghandler.py 1.2 => 1.3 ===
--- Zope/lib/python/ZConfig/components/logger/loghandler.py:1.2 Tue Apr 13 13:05:52 2004
+++ Zope/lib/python/ZConfig/components/logger/loghandler.py Thu Apr 22 16:20:11 2004
@@ -17,7 +17,7 @@
import sys
from logging import Handler, StreamHandler
-from logging.handlers import SysLogHandler
+from logging.handlers import SysLogHandler, BufferingHandler
from logging.handlers import HTTPHandler, SMTPHandler
from logging.handlers import NTEventLogHandler as Win32EventLogHandler
@@ -53,32 +53,19 @@
pass
-class StartupHandler(Handler):
- """
- A handler which outputs messages to a stream but also buffers them until
- they can be flushed to a target handler. Useful at startup before we can
- know that we can safely write to a config-specified handler.
+class StartupHandler(BufferingHandler):
+ """Handler which stores messages in a buffer until later.
+
+ This is useful at startup before we can know that we can safely
+ write to a configuration-specified handler.
"""
- def __init__(self, stream=None):
- Handler.__init__(self)
- if not stream:
- stream = sys.stderr
- self.stream = stream
- self.buffer = []
- def emit(self, record):
- try:
- self.buffer.append(record)
- msg = self.format(record)
- self.stream.write("%s\n" % msg)
- self.flush()
- except:
- self.handleError(record)
+ def __init__(self):
+ BufferingHandler.__init__(self, sys.maxint)
- def flush(self):
- self.stream.flush()
+ def shouldFlush(self, record):
+ return False
def flushBufferTo(self, target):
- for record in self.buffer:
- target.handle(record)
- self.buffer = []
+ while self.buffer:
+ target.handle(self.buffer.pop(0))
More information about the Zope3-Checkins
mailing list