Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

Commit

Permalink
core: raise better errors on common logging block syntax mistakes
Browse files Browse the repository at this point in the history
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:<netname> empty: this causes it to become None, so using get() on it fails.
  • Loading branch information
jlu5 committed Sep 9, 2017
1 parent 93704d8 commit 49136d5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
13 changes: 10 additions & 3 deletions classes.py
Expand Up @@ -90,20 +90,27 @@ def logSetup(self):
"""
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)
Expand Down
6 changes: 5 additions & 1 deletion log.py
Expand Up @@ -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
Expand Down

0 comments on commit 49136d5

Please sign in to comment.