Commit 9502132a authored by Fred Drake's avatar Fred Drake

Make sure the datatype for the "logger" section type adds a NullHandler if

no other handlers are provided.  This is needed to avoid warnings on stderr
from the logging package.
parent 0b4df6fc
......@@ -235,8 +235,12 @@ class LoggerWrapper:
logger.handlers = []
logger.propagate = 0
logger.setLevel(self.level)
for handler_factory in self.handler_factories:
handler = handler_factory()
logger.addHandler(handler)
if self.handler_factories:
for handler_factory in self.handler_factories:
handler = handler_factory()
logger.addHandler(handler)
else:
from zLOG.LogHandlers import NullHandler
logger.addHandler(NullHandler())
self.resolved = logger
return self.resolved
......@@ -19,6 +19,7 @@ import logging
import unittest
import ZConfig
import zLOG.LogHandlers
import zLOG.tests
......@@ -54,7 +55,11 @@ class TestzLOGConfig(unittest.TestCase):
self.assertEqual(conf.logger.level, logging.INFO)
logger = conf.logger()
self.assert_(isinstance(logger, logging.Logger))
self.assertEqual(logger.handlers, [])
# Make sure there's a NullHandler, since a warning gets
# printed if there are no handlers:
self.assertEqual(len(logger.handlers), 1)
self.assert_(isinstance(logger.handlers[0],
zLOG.LogHandlers.NullHandler))
# XXX need to make sure each loghandler datatype gets exercised.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment