issue #539: disable logger propagation.

pull/564/head
David Wilson 6 years ago
parent 1c955a9876
commit ae5a471e31

@ -75,25 +75,28 @@ class Handler(logging.Handler):
def setup(): def setup():
""" """
Install a handler for Mitogen's logger to redirect it into the Ansible Install handlers for Mitogen loggers to redirect them into the Ansible
display framework, and prevent propagation to the root logger. display framework. Ansible installs its own logging framework handlers when
C.DEFAULT_LOG_PATH is set, therefore disable propagation for our handlers.
""" """
logging.getLogger('ansible_mitogen').handlers = [Handler(display.vvv)] l_mitogen = logging.getLogger('mitogen')
mitogen.core.LOG.handlers = [Handler(display.vvv)] l_mitogen_io = logging.getLogger('mitogen.io')
mitogen.core.IOLOG.handlers = [Handler(display.vvvv)] l_ansible_mitogen = logging.getLogger('ansible_mitogen')
mitogen.core.IOLOG.propagate = False
for logger in l_mitogen, l_mitogen_io, l_ansible_mitogen:
logger.handlers = [Handler(display.vvv)]
logger.propagate = False
if display.verbosity > 2: if display.verbosity > 2:
mitogen.core.LOG.setLevel(logging.DEBUG) l_ansible_mitogen.setLevel(logging.DEBUG)
logging.getLogger('ansible_mitogen').setLevel(logging.DEBUG) l_mitogen.setLevel(logging.DEBUG)
else: else:
# Mitogen copies the active log level into new children, allowing them # Mitogen copies the active log level into new children, allowing them
# to filter tiny messages before they hit the network, and therefore # to filter tiny messages before they hit the network, and therefore
# before they wake the IO loop. Explicitly setting INFO saves ~4% # before they wake the IO loop. Explicitly setting INFO saves ~4%
# running against just the local machine. # running against just the local machine.
mitogen.core.LOG.setLevel(logging.ERROR) l_mitogen.setLevel(logging.ERROR)
logging.getLogger('ansible_mitogen').setLevel(logging.ERROR) l_ansible_mitogen.setLevel(logging.ERROR)
if display.verbosity > 3: if display.verbosity > 3:
mitogen.core.IOLOG.setLevel(logging.DEBUG) l_mitogen_io.setLevel(logging.DEBUG)
logging.getLogger('ansible_mitogen').setLevel(logging.DEBUG)

Loading…
Cancel
Save