Add :debug-loglevel :debug-logfilter commands
This commit is contained in:
parent
d25fde4f29
commit
1d5a3a6175
@ -256,3 +256,32 @@ def window_only(current_win_id):
|
|||||||
for win_id, window in objreg.window_registry.items():
|
for win_id, window in objreg.window_registry.items():
|
||||||
if win_id != current_win_id:
|
if win_id != current_win_id:
|
||||||
window.close()
|
window.close()
|
||||||
|
|
||||||
|
|
||||||
|
@cmdutils.register(debug=True)
|
||||||
|
@cmdutils.argument('level', choices=[level.lower()
|
||||||
|
for level in log.LOG_LEVELS])
|
||||||
|
def debug_log_level(level: str):
|
||||||
|
"""Change the log level for console logging.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
level: log level for console log.
|
||||||
|
"""
|
||||||
|
log.console_handler.setLevel(log.LOG_LEVELS[level.upper()])
|
||||||
|
|
||||||
|
|
||||||
|
@cmdutils.register(debug=True)
|
||||||
|
def debug_log_filter(filter_names: str):
|
||||||
|
"""Change the log filter for console logging.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
filter_names: log filters for console log.
|
||||||
|
"""
|
||||||
|
if set(filter_names.split(',')).issubset(log.LOGGER_NAMES):
|
||||||
|
log.console_handler.removeFilter(log.console_filter)
|
||||||
|
log.console_filter = log.LogFilter(filter_names.split(','))
|
||||||
|
log.console_handler.addFilter(log.console_filter)
|
||||||
|
else:
|
||||||
|
raise cmdexc.CommandError("Invalid argument, {} choose from {}".
|
||||||
|
format(
|
||||||
|
filter_names, ','.join(log.LOGGER_NAMES)))
|
||||||
|
@ -87,6 +87,15 @@ LOG_LEVELS = {
|
|||||||
'CRITICAL': logging.CRITICAL,
|
'CRITICAL': logging.CRITICAL,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOGGER_NAMES = [
|
||||||
|
'statusbar', 'completion', 'init', 'url',
|
||||||
|
'destroy', 'modes', 'webview', 'misc',
|
||||||
|
'mouse', 'procs', 'hints', 'keyboard',
|
||||||
|
'commands', 'signals', 'downloads',
|
||||||
|
'js', 'qt', 'rfc6266', 'ipc', 'shlexer',
|
||||||
|
'save', 'message', 'config', 'sessions'
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def vdebug(self, msg, *args, **kwargs):
|
def vdebug(self, msg, *args, **kwargs):
|
||||||
"""Log with a VDEBUG level.
|
"""Log with a VDEBUG level.
|
||||||
@ -131,6 +140,8 @@ sessions = logging.getLogger('sessions')
|
|||||||
|
|
||||||
|
|
||||||
ram_handler = None
|
ram_handler = None
|
||||||
|
console_handler = None
|
||||||
|
console_filter = None
|
||||||
|
|
||||||
|
|
||||||
def stub(suffix=''):
|
def stub(suffix=''):
|
||||||
@ -149,6 +160,7 @@ class CriticalQtWarning(Exception):
|
|||||||
|
|
||||||
def init_log(args):
|
def init_log(args):
|
||||||
"""Init loggers based on the argparse namespace passed."""
|
"""Init loggers based on the argparse namespace passed."""
|
||||||
|
global console
|
||||||
level = args.loglevel.upper()
|
level = args.loglevel.upper()
|
||||||
try:
|
try:
|
||||||
numeric_level = getattr(logging, level)
|
numeric_level = getattr(logging, level)
|
||||||
@ -161,9 +173,11 @@ def init_log(args):
|
|||||||
console, ram = _init_handlers(numeric_level, args.color, args.force_color,
|
console, ram = _init_handlers(numeric_level, args.color, args.force_color,
|
||||||
args.json_logging, args.loglines)
|
args.json_logging, args.loglines)
|
||||||
root = logging.getLogger()
|
root = logging.getLogger()
|
||||||
|
global console_filter
|
||||||
if console is not None:
|
if console is not None:
|
||||||
if args.logfilter is not None:
|
if args.logfilter is not None:
|
||||||
console.addFilter(LogFilter(args.logfilter.split(',')))
|
console_filter = LogFilter(args.logfilter.split(','))
|
||||||
|
console.addFilter(console_filter)
|
||||||
root.addHandler(console)
|
root.addHandler(console)
|
||||||
if ram is not None:
|
if ram is not None:
|
||||||
root.addHandler(ram)
|
root.addHandler(ram)
|
||||||
@ -175,6 +189,10 @@ def init_log(args):
|
|||||||
_log_inited = True
|
_log_inited = True
|
||||||
|
|
||||||
|
|
||||||
|
def change(filters):
|
||||||
|
console.addFilter(LogFilter(filters.split(',')))
|
||||||
|
|
||||||
|
|
||||||
def _init_py_warnings():
|
def _init_py_warnings():
|
||||||
"""Initialize Python warning handling."""
|
"""Initialize Python warning handling."""
|
||||||
warnings.simplefilter('default')
|
warnings.simplefilter('default')
|
||||||
@ -210,6 +228,7 @@ def _init_handlers(level, color, force_color, json_logging, ram_capacity):
|
|||||||
json_logging: Output log lines in JSON (this disables all colors).
|
json_logging: Output log lines in JSON (this disables all colors).
|
||||||
"""
|
"""
|
||||||
global ram_handler
|
global ram_handler
|
||||||
|
global console_handler
|
||||||
console_fmt, ram_fmt, html_fmt, use_colorama = _init_formatters(
|
console_fmt, ram_fmt, html_fmt, use_colorama = _init_formatters(
|
||||||
level, color, force_color, json_logging)
|
level, color, force_color, json_logging)
|
||||||
|
|
||||||
@ -236,6 +255,11 @@ def _init_handlers(level, color, force_color, json_logging, ram_capacity):
|
|||||||
return console_handler, ram_handler
|
return console_handler, ram_handler
|
||||||
|
|
||||||
|
|
||||||
|
def change_loglevel(level):
|
||||||
|
value = LOG_LEVELS[level.upper()]
|
||||||
|
console_handler.setLevel(value)
|
||||||
|
|
||||||
|
|
||||||
def _init_formatters(level, color, force_color, json_logging):
|
def _init_formatters(level, color, force_color, json_logging):
|
||||||
"""Init log formatters.
|
"""Init log formatters.
|
||||||
|
|
||||||
|
@ -474,7 +474,7 @@ Feature: Various utility commands.
|
|||||||
## https://github.com/The-Compiler/qutebrowser/issues/1523
|
## https://github.com/The-Compiler/qutebrowser/issues/1523
|
||||||
|
|
||||||
Scenario: Completing a single option argument
|
Scenario: Completing a single option argument
|
||||||
When I run :set-cmd-text -s :--
|
When I run :set-cmd-text -s :--
|
||||||
Then no crash should happen
|
Then no crash should happen
|
||||||
|
|
||||||
## https://github.com/The-Compiler/qutebrowser/issues/1386
|
## https://github.com/The-Compiler/qutebrowser/issues/1386
|
||||||
|
Loading…
Reference in New Issue
Block a user