From 49136d5abd609fd5e3ba2ec2e42a0443118e62ab Mon Sep 17 00:00:00 2001 From: James Lu Date: Fri, 8 Sep 2017 19:04:49 -0700 Subject: [PATCH] core: raise better errors on common logging block syntax mistakes These are commonly reported and include: - Commenting out the contents of logging:channels without commenting out the "channels:" heading, causing that block to become None. - Commenting out headers like "filerotation:", causing its body to become pairs in logging:files or something similar. - Leaving logging:channels: empty: this causes it to become None, so using get() on it fails. --- classes.py | 13 ++++++++++--- log.py | 6 +++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/classes.py b/classes.py index 59115e6..1b2e983 100644 --- a/classes.py +++ b/classes.py @@ -90,20 +90,27 @@ class Irc(utils.DeprecatedAttributesObject): """ try: channels = conf.conf['logging']['channels'][self.name] - except KeyError: # Not set up; just ignore. + except (KeyError, TypeError): # Not set up; just ignore. return log.debug('(%s) Setting up channel logging to channels %r', self.name, channels) + # Only create handlers if they haven't already been set up. if not self.loghandlers: - # Only create handlers if they haven't already been set up. + if not isinstance(channels, dict): + log.warning('(%s) Got invalid channel logging configuration %r; are your indentation ' + 'and block commenting consistent?', self.name, channels) + return for channel, chandata in channels.items(): # Fetch the log level for this channel block. level = None - if chandata is not None: + if isinstance(chandata, dict): level = chandata.get('loglevel') + else: + log.warning('(%s) Got invalid channel logging pair %r: %r; are your indentation ' + 'and block commenting consistent?', self.name, filename, config) handler = PyLinkChannelLogger(self, channel, level=level) self.loghandlers.append(handler) diff --git a/log.py b/log.py index eee8cad..bddc9d3 100644 --- a/log.py +++ b/log.py @@ -87,7 +87,11 @@ def stopFileLoggers(): files = conf.conf['logging'].get('files') if files: for filename, config in files.items(): - makeFileLogger(filename, config.get('loglevel')) + if isinstance(config, dict): + makeFileLogger(filename, config.get('loglevel')) + else: + log.warning('Got invalid file logging pair %r: %r; are your indentation and block ' + 'commenting consistent?', filename, config) log.debug("log: Emptying log_queue") # Process and empty the log queue