From 8fc1eac6ae371c7815c4dc6aa564e34a11317deb Mon Sep 17 00:00:00 2001 From: David Wilson Date: Wed, 2 May 2018 20:35:17 +0100 Subject: [PATCH] utils: combine MITOGEN_LOG_LEVEL and MITOGEN_LOG_IO. Saves lots of readline fiddling. --- docs/getting_started.rst | 10 +++++----- mitogen/utils.py | 9 +++++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/docs/getting_started.rst b/docs/getting_started.rst index 3b50e757..aec86bd7 100644 --- a/docs/getting_started.rst +++ b/docs/getting_started.rst @@ -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 diff --git a/mitogen/utils.py b/mitogen/utils.py index ab8a673a..480940ab 100644 --- a/mitogen/utils.py +++ b/mitogen/utils.py @@ -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)