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.
|
module.
|
||||||
|
|
||||||
When starting qutebrowser with the `--debug` flag, you also get useful debug
|
When starting qutebrowser with the `--debug` flag, you also get useful debug
|
||||||
logs. You can add +--logfilter _category[,category,...]_+ to restrict logging
|
logs. You can add +--logfilter _[!]category[,category,...]_+ to restrict
|
||||||
to the given categories.
|
logging to the given categories.
|
||||||
|
|
||||||
With `--debug` there are also some additional +debug-_*_+ commands available,
|
With `--debug` there are also some additional +debug-_*_+ commands available,
|
||||||
for example `:debug-all-objects` and `:debug-all-widgets` which print a list of
|
for example `:debug-all-objects` and `:debug-all-widgets` which print a list of
|
||||||
|
@ -146,7 +146,7 @@ def logfilter_error(logfilter):
|
|||||||
Args:
|
Args:
|
||||||
logfilter: A comma separated list of logger names.
|
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
|
return logfilter
|
||||||
else:
|
else:
|
||||||
raise argparse.ArgumentTypeError(
|
raise argparse.ArgumentTypeError(
|
||||||
|
@ -182,9 +182,16 @@ def init_log(args):
|
|||||||
root = logging.getLogger()
|
root = logging.getLogger()
|
||||||
global console_filter
|
global console_filter
|
||||||
if console is not None:
|
if console is not None:
|
||||||
console_filter = LogFilter(None)
|
if not args.logfilter:
|
||||||
if args.logfilter is not None:
|
negate = False
|
||||||
console_filter.names = args.logfilter.split(',')
|
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)
|
console.addFilter(console_filter)
|
||||||
root.addHandler(console)
|
root.addHandler(console)
|
||||||
if ram is not None:
|
if ram is not None:
|
||||||
@ -498,12 +505,14 @@ class LogFilter(logging.Filter):
|
|||||||
comma-separated list instead.
|
comma-separated list instead.
|
||||||
|
|
||||||
Attributes:
|
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__()
|
super().__init__()
|
||||||
self.names = names
|
self.names = names
|
||||||
|
self.negated = negate
|
||||||
|
|
||||||
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."""
|
||||||
@ -514,12 +523,12 @@ class LogFilter(logging.Filter):
|
|||||||
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 not self.negated
|
||||||
elif not record.name.startswith(name):
|
elif not record.name.startswith(name):
|
||||||
continue
|
continue
|
||||||
elif record.name[len(name)] == '.':
|
elif record.name[len(name)] == '.':
|
||||||
return True
|
return not self.negated
|
||||||
return False
|
return self.negated
|
||||||
|
|
||||||
|
|
||||||
class RAMHandler(logging.Handler):
|
class RAMHandler(logging.Handler):
|
||||||
|
Loading…
Reference in New Issue
Block a user