utils: combine MITOGEN_LOG_LEVEL and MITOGEN_LOG_IO.

Saves lots of readline fiddling.
pull/244/head
David Wilson 7 years ago
parent f5238fe791
commit 8fc1eac6ae

@ -115,15 +115,15 @@ Logging Environment Variables
Overrides the :py:mod:`logging` package log level set by any call to
:py:func:`mitogen.utils.log_to_file`. Defaults to ``INFO``.
If set to ``IO``, equivalent to ``DEBUG`` but additionally enabled IO
logging for any call to :py:func:`mitogen.utils.log_to_file`. IO logging
produces verbose records of any IO interaction, which is useful for
debugging hangs and deadlocks.
``MITOGEN_LOG_USEC``
If present, forces microsecond-level timestamps for any call to
:py:func:`mitogen.utils.log_to_file`.
``MITOGEN_LOG_IO``
If present, forces IO logging for any call to
:py:func:`mitogen.utils.log_to_file`. IO logging produces extremely verbose
logs of any IO interaction, which is useful when debugging deadlocks.
Logging Records

@ -71,13 +71,14 @@ def log_to_file(path=None, io=False, usec=False, level='INFO'):
fp = sys.stderr
level = os.environ.get('MITOGEN_LOG_LEVEL', level).upper()
level = getattr(logging, level, logging.INFO)
log.setLevel(level)
io = ('MITOGEN_LOG_IO' in os.environ) or io
io = level == 'IO'
if io:
level = 'DEBUG'
logging.getLogger('mitogen.io').setLevel(level)
level = getattr(logging, level, logging.INFO)
log.setLevel(level)
handler = logging.StreamHandler(fp)
handler.formatter = log_get_formatter(usec=usec)
log.handlers.insert(0, handler)

Loading…
Cancel
Save