Simplify :debug-log-filter implementation

This commit is contained in:
Florian Bruhin 2016-08-19 15:08:15 +02:00
parent e1cd905163
commit 7e3d1ccd24
2 changed files with 4 additions and 6 deletions

View File

@ -270,9 +270,7 @@ def debug_log_filter(filters: str):
filters: log filters for console log.
"""
if set(filters.split(',')).issubset(log.LOGGER_NAMES):
log.console_handler.removeFilter(log.console_filter)
log.console_filter = log.LogFilter(filters.split(','))
log.console_handler.addFilter(log.console_filter)
log.console_filter.names = filters.split(',')
else:
raise cmdexc.CommandError("filters: Invalid value {} - expected one "
"of: {}".format(filters,

View File

@ -467,16 +467,16 @@ class LogFilter(logging.Filter):
def __init__(self, names):
super().__init__()
self._names = names
self.names = names
def filter(self, record):
"""Determine if the specified record is to be logged."""
if self._names is None:
if self.names is None:
return True
if record.levelno > logging.DEBUG:
# More important than DEBUG, so we won't filter at all
return True
for name in self._names:
for name in self.names:
if record.name == name:
return True
elif not record.name.startswith(name):