Merge "log: Introduce _iter_loggers"

This commit is contained in:
Jenkins 2016-07-06 17:50:40 +00:00 committed by Gerrit Code Review
commit 6f7c4584c6
2 changed files with 22 additions and 0 deletions

View File

@ -79,6 +79,22 @@ def _get_log_file_path(conf, binary=None):
return None
def _iter_loggers():
"""Iterate on existing loggers."""
# Sadly, Logger.manager and Manager.loggerDict are not documented,
# but there is no logging public function to iterate on all loggers.
# The root logger is not part of loggerDict.
yield logging.getLogger()
manager = logging.Logger.manager
for logger in manager.loggerDict.values():
if isinstance(logger, logging.PlaceHolder):
continue
yield logger
class BaseLoggerAdapter(logging.LoggerAdapter):
warn = logging.LoggerAdapter.warning

View File

@ -215,6 +215,12 @@ class LogHandlerTestCase(BaseTestCase):
binary=prefix),
expected)
def test_iter_loggers(self):
mylog = logging.getLogger("abc.cde")
loggers = list(log._iter_loggers())
self.assertIn(logging.getLogger(), loggers)
self.assertIn(mylog, loggers)
class SysLogHandlersTestCase(BaseTestCase):
"""Test the standard Syslog handler."""