logging: Catch errors when loading logging/config_file

This commit is contained in:
Thomas Adamcik 2015-12-05 22:44:39 +01:00
parent 3e259f1c00
commit ede5b8abff
2 changed files with 11 additions and 2 deletions

View File

@ -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
-------

View File

@ -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: