Allow negating categories in --logfilter
Sometimes I want to see all the logs _except_ for the sql stuff and "marked cookies as dirty". with this you should be able to pass `--logfilter \!sql,save`.
This commit is contained in:
parent
5e99da5459
commit
addd2e74ce
@ -188,8 +188,8 @@ There are some useful functions for debugging in the `qutebrowser.utils.debug`
|
||||
module.
|
||||
|
||||
When starting qutebrowser with the `--debug` flag, you also get useful debug
|
||||
logs. You can add +--logfilter _category[,category,...]_+ to restrict logging
|
||||
to the given categories.
|
||||
logs. You can add +--logfilter _[!]category[,category,...]_+ to restrict
|
||||
logging to the given categories.
|
||||
|
||||
With `--debug` there are also some additional +debug-_*_+ commands available,
|
||||
for example `:debug-all-objects` and `:debug-all-widgets` which print a list of
|
||||
|
@ -146,7 +146,7 @@ def logfilter_error(logfilter):
|
||||
Args:
|
||||
logfilter: A comma separated list of logger names.
|
||||
"""
|
||||
if set(logfilter.split(',')).issubset(log.LOGGER_NAMES):
|
||||
if set(logfilter.lstrip('!').split(',')).issubset(log.LOGGER_NAMES):
|
||||
return logfilter
|
||||
else:
|
||||
raise argparse.ArgumentTypeError(
|
||||
|
@ -182,9 +182,16 @@ def init_log(args):
|
||||
root = logging.getLogger()
|
||||
global console_filter
|
||||
if console is not None:
|
||||
console_filter = LogFilter(None)
|
||||
if args.logfilter is not None:
|
||||
console_filter.names = args.logfilter.split(',')
|
||||
if not args.logfilter:
|
||||
negate = False
|
||||
names = None
|
||||
elif args.logfilter.startswith('!'):
|
||||
negate = True
|
||||
names = args.logfilter[1:].split(',')
|
||||
else:
|
||||
negate = False
|
||||
names = args.logfilter.split(',')
|
||||
console_filter = LogFilter(names, negate)
|
||||
console.addFilter(console_filter)
|
||||
root.addHandler(console)
|
||||
if ram is not None:
|
||||
@ -498,12 +505,14 @@ class LogFilter(logging.Filter):
|
||||
comma-separated list instead.
|
||||
|
||||
Attributes:
|
||||
_names: A list of names that should be logged.
|
||||
names: A list of record names to filter.
|
||||
negated: Wether names is a list of records to log or to suppress.
|
||||
"""
|
||||
|
||||
def __init__(self, names):
|
||||
def __init__(self, names, negate=False):
|
||||
super().__init__()
|
||||
self.names = names
|
||||
self.negated = negate
|
||||
|
||||
def filter(self, record):
|
||||
"""Determine if the specified record is to be logged."""
|
||||
@ -514,12 +523,12 @@ class LogFilter(logging.Filter):
|
||||
return True
|
||||
for name in self.names:
|
||||
if record.name == name:
|
||||
return True
|
||||
return not self.negated
|
||||
elif not record.name.startswith(name):
|
||||
continue
|
||||
elif record.name[len(name)] == '.':
|
||||
return True
|
||||
return False
|
||||
return not self.negated
|
||||
return self.negated
|
||||
|
||||
|
||||
class RAMHandler(logging.Handler):
|
||||
|
Loading…
Reference in New Issue
Block a user