From df67d708db5c6ff39b7b3d1cc02e7d5deb259c18 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Thu, 12 Feb 2015 17:52:52 +0100 Subject: [PATCH 1/3] config: Add support for 'all' loglevel Equal to logging.NOTSET or 0 in the logging module. --- docs/changelog.rst | 8 +++++++- mopidy/config/types.py | 5 +++-- tests/config/test_types.py | 13 ++++++++----- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 1a9eb33d..5581bfec 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -26,6 +26,12 @@ v0.20.0 (UNRELEASED) - Make the ``mopidy`` command print a friendly error message if the :mod:`gobject` Python module cannot be imported. (Fixes: :issue:`836`) +**Configuration** + +- Add support for the log level value ``all`` to the loglevels configurations. + This can be used to show absolutely all log records, including those at + custom levels below ``DEBUG``. + **Local backend** - Add cover URL to all scanned files with MusicBrainz album IDs. (Fixes: @@ -50,7 +56,7 @@ v0.20.0 (UNRELEASED) - Enable browsing of artist references, in addition to albums and playlists. (PR: :issue:`884`) - + - Share a single mapping between names and URIs across all MPD sessions. (Fixes: :issue:`934`, PR: :issue:`968`) diff --git a/mopidy/config/types.py b/mopidy/config/types.py index bed03fa2..785ec55a 100644 --- a/mopidy/config/types.py +++ b/mopidy/config/types.py @@ -200,8 +200,8 @@ class List(ConfigValue): class LogLevel(ConfigValue): """Log level value. - Expects one of ``critical``, ``error``, ``warning``, ``info``, ``debug`` - with any casing. + Expects one of ``critical``, ``error``, ``warning``, ``info``, ``debug``, + or ``all``, with any casing. """ levels = { b'critical': logging.CRITICAL, @@ -209,6 +209,7 @@ class LogLevel(ConfigValue): b'warning': logging.WARNING, b'info': logging.INFO, b'debug': logging.DEBUG, + b'all': logging.NOTSET, } def deserialize(self, value): diff --git a/tests/config/test_types.py b/tests/config/test_types.py index 939d028b..365fa9e0 100644 --- a/tests/config/test_types.py +++ b/tests/config/test_types.py @@ -281,11 +281,14 @@ class ListTest(unittest.TestCase): class LogLevelTest(unittest.TestCase): - levels = {'critical': logging.CRITICAL, - 'error': logging.ERROR, - 'warning': logging.WARNING, - 'info': logging.INFO, - 'debug': logging.DEBUG} + levels = { + 'critical': logging.CRITICAL, + 'error': logging.ERROR, + 'warning': logging.WARNING, + 'info': logging.INFO, + 'debug': logging.DEBUG, + 'all': logging.NOTSET, + } def test_deserialize_conversion_success(self): value = types.LogLevel() From 79dbc652e0084b358c50bcbbedda3da13a75de56 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Thu, 12 Feb 2015 18:03:13 +0100 Subject: [PATCH 2/3] log: Define TRACE log level with name and color --- docs/changelog.rst | 5 +++++ mopidy/utils/log.py | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index 5581bfec..413e2ca9 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -32,6 +32,11 @@ v0.20.0 (UNRELEASED) This can be used to show absolutely all log records, including those at custom levels below ``DEBUG``. +**Logging** + +- Add custom log level ``TRACE`` (numerical level 5), which can be used by + Mopidy and extensions to log at an even more detailed level than ``DEBUG``. + **Local backend** - Add cover URL to all scanned files with MusicBrainz album IDs. (Fixes: diff --git a/mopidy/utils/log.py b/mopidy/utils/log.py index 396c05b9..79ec723c 100644 --- a/mopidy/utils/log.py +++ b/mopidy/utils/log.py @@ -14,6 +14,9 @@ LOG_LEVELS = { 3: dict(root=logging.DEBUG, mopidy=logging.DEBUG), } +# Custom log level which has even lower priority than DEBUG +TRACE_LOG_LEVEL = 5 + class DelayedHandler(logging.Handler): def __init__(self): @@ -42,6 +45,8 @@ def bootstrap_delayed_logging(): def setup_logging(config, verbosity_level, save_debug_log): + logging.addLevelName(TRACE_LOG_LEVEL, 'TRACE') + logging.captureWarnings(True) if config['logging']['config_file']: @@ -137,6 +142,7 @@ class ColorizingStreamHandler(logging.StreamHandler): # Map logging levels to (background, foreground, bold/intense) level_map = { + TRACE_LOG_LEVEL: (None, 'blue', False), logging.DEBUG: (None, 'blue', False), logging.INFO: (None, 'white', False), logging.WARNING: (None, 'yellow', False), From ece54b68d1010b3e0da3b2dd7666a3358e1c6d11 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Thu, 12 Feb 2015 19:29:14 +0100 Subject: [PATCH 3/3] log: Support -vvvv to not filter logs at all --- docs/changelog.rst | 4 ++++ mopidy/utils/log.py | 1 + 2 files changed, 5 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index 413e2ca9..89090218 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -26,6 +26,10 @@ v0.20.0 (UNRELEASED) - Make the ``mopidy`` command print a friendly error message if the :mod:`gobject` Python module cannot be imported. (Fixes: :issue:`836`) +- Add support for repeating the :cmdoption:`-v ` argument four times + to set the log level for all loggers to the lowest possible value, including + log records at levels lover than ``DEBUG`` too. + **Configuration** - Add support for the log level value ``all`` to the loglevels configurations. diff --git a/mopidy/utils/log.py b/mopidy/utils/log.py index 79ec723c..3c7ee599 100644 --- a/mopidy/utils/log.py +++ b/mopidy/utils/log.py @@ -12,6 +12,7 @@ LOG_LEVELS = { 1: dict(root=logging.WARNING, mopidy=logging.DEBUG), 2: dict(root=logging.INFO, mopidy=logging.DEBUG), 3: dict(root=logging.DEBUG, mopidy=logging.DEBUG), + 4: dict(root=logging.NOTSET, mopidy=logging.NOTSET), } # Custom log level which has even lower priority than DEBUG