master: annotate LogForwarder messages.

mitogen/master.py:
    Annotate forwarded log entries with their original source, logger
    name, and message.

ansible:
    mark stderr in red with -vvv

    Tempting to make this appaer 100% of the time, but some crappy
    bashrcs may cause lots of junk to be printed.
pull/220/head
David Wilson 6 years ago
parent 9d0949eb99
commit 6fb3a76e68

@ -46,6 +46,9 @@ class Handler(logging.Handler):
self.normal_method = normal_method
def emit(self, record):
if getattr(record, 'mitogen_name', '') == 'stderr':
record.levelno = logging.ERROR
s = '[pid %d] %s' % (os.getpid(), self.format(record))
if record.levelno >= logging.ERROR:
self.display.error(s, wrap_text=False)

@ -125,6 +125,19 @@ Logging Environment Variables
logs of any IO interaction, which is useful when debugging deadlocks.
Logging Records
~~~~~~~~~~~~~~~
Messages received from a child context via :class:`mitogen.master.LogForwarder`
receive extra attributes:
* `mitogen_context`: :class:`mitogen.master.Context` referring to the message
source.
* `mitogen_name`: original logger name in the source context.
* `mitogen_msg`: original message in the source context.
Creating A Context
------------------

@ -309,7 +309,11 @@ class LogForwarder(object):
self._cache[msg.src_id] = logger = logging.getLogger(name)
name, level_s, s = msg.data.split('\x00', 2)
logger.log(int(level_s), '%s: %s', name, s)
logger.log(int(level_s), '%s: %s', name, s, extra={
'mitogen_message': s,
'mitogen_context': self._router.context_by_id(msg.src_id),
'mitogen_name': name,
})
def __repr__(self):
return 'LogForwarder(%r)' % (self._router,)

Loading…
Cancel
Save