From 60254120508384f5b5735668333e77fbdfdfb0d5 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Sat, 23 Jun 2018 20:11:22 +0100 Subject: [PATCH] issue #272: add a blacklist for noisy target loggers --- ansible_mitogen/logging.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ansible_mitogen/logging.py b/ansible_mitogen/logging.py index 33d49831..3d14377b 100644 --- a/ansible_mitogen/logging.py +++ b/ansible_mitogen/logging.py @@ -45,9 +45,20 @@ class Handler(logging.Handler): self.display = display self.normal_method = normal_method + #: Set of target loggers that produce warnings and errors that spam the + #: console needlessly. Their log level is forced to INFO. A better strategy + #: may simply be to bury all target logs in DEBUG output, but not by + #: overriding their log level as done here. + NOISY_LOGGERS = frozenset([ + 'dnf', # issue #272; warns when a package is already installed. + ]) + def emit(self, record): - if getattr(record, 'mitogen_name', '') == 'stderr': + mitogen_name = getattr(record, 'mitogen_name', '') + if mitogen_name == 'stderr': record.levelno = logging.ERROR + if mitogen_name in self.NOISY_LOGGERS and record.levelno >= logging.WARNING: + record.levelno = logging.DEBUG s = '[pid %d] %s' % (os.getpid(), self.format(record)) if record.levelno >= logging.ERROR: