Simplify :debug-log-filter implementation
This commit is contained in:
parent
e1cd905163
commit
7e3d1ccd24
@ -270,9 +270,7 @@ def debug_log_filter(filters: str):
|
|||||||
filters: log filters for console log.
|
filters: log filters for console log.
|
||||||
"""
|
"""
|
||||||
if set(filters.split(',')).issubset(log.LOGGER_NAMES):
|
if set(filters.split(',')).issubset(log.LOGGER_NAMES):
|
||||||
log.console_handler.removeFilter(log.console_filter)
|
log.console_filter.names = filters.split(',')
|
||||||
log.console_filter = log.LogFilter(filters.split(','))
|
|
||||||
log.console_handler.addFilter(log.console_filter)
|
|
||||||
else:
|
else:
|
||||||
raise cmdexc.CommandError("filters: Invalid value {} - expected one "
|
raise cmdexc.CommandError("filters: Invalid value {} - expected one "
|
||||||
"of: {}".format(filters,
|
"of: {}".format(filters,
|
||||||
|
@ -467,16 +467,16 @@ class LogFilter(logging.Filter):
|
|||||||
|
|
||||||
def __init__(self, names):
|
def __init__(self, names):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self._names = names
|
self.names = names
|
||||||
|
|
||||||
def filter(self, record):
|
def filter(self, record):
|
||||||
"""Determine if the specified record is to be logged."""
|
"""Determine if the specified record is to be logged."""
|
||||||
if self._names is None:
|
if self.names is None:
|
||||||
return True
|
return True
|
||||||
if record.levelno > logging.DEBUG:
|
if record.levelno > logging.DEBUG:
|
||||||
# More important than DEBUG, so we won't filter at all
|
# More important than DEBUG, so we won't filter at all
|
||||||
return True
|
return True
|
||||||
for name in self._names:
|
for name in self.names:
|
||||||
if record.name == name:
|
if record.name == name:
|
||||||
return True
|
return True
|
||||||
elif not record.name.startswith(name):
|
elif not record.name.startswith(name):
|
||||||
|
Loading…
Reference in New Issue
Block a user