Merge "log: Introduce _iter_loggers"
This commit is contained in:
commit
6f7c4584c6
@ -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
|
||||
|
@ -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."""
|
||||
|
Loading…
Reference in New Issue
Block a user