From ede5b8abff6ff269f7180288f98ff1f68c3de1fc Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Sat, 5 Dec 2015 22:44:39 +0100 Subject: [PATCH] logging: Catch errors when loading logging/config_file --- docs/changelog.rst | 3 +++ mopidy/internal/log.py | 10 ++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 4c304be1..49b7f263 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -90,6 +90,9 @@ Cleanups - The ``on_event`` handler in our listener helper now catches exceptions. This means that any errors in event handling won't crash the actor in question. +- Catch errors when loading :confval:`logging/config_file`. + (Fixes: :issue:`1320`) + Gapless ------- diff --git a/mopidy/internal/log.py b/mopidy/internal/log.py index 9c40da4f..011a70d2 100644 --- a/mopidy/internal/log.py +++ b/mopidy/internal/log.py @@ -19,6 +19,8 @@ LOG_LEVELS = { TRACE_LOG_LEVEL = 5 logging.addLevelName(TRACE_LOG_LEVEL, 'TRACE') +logger = logging.getLogger(__name__) + class DelayedHandler(logging.Handler): @@ -54,8 +56,12 @@ def setup_logging(config, verbosity_level, save_debug_log): if config['logging']['config_file']: # Logging config from file must be read before other handlers are # added. If not, the other handlers will have no effect. - logging.config.fileConfig(config['logging']['config_file'], - disable_existing_loggers=False) + try: + path = config['logging']['config_file'] + logging.config.fileConfig(path, disable_existing_loggers=False) + except Exception as e: + # Catch everything as logging does not specify what can go wrong. + logger.error('Loading logging config %r failed. %s', path, e) setup_console_logging(config, verbosity_level) if save_debug_log: