diff options
author | Florian Bruhin <me@the-compiler.org> | 2021-05-28 15:46:35 +0200 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2021-05-28 15:46:35 +0200 |
commit | 40477e826c9ec73a8f99177df645094be3ef5ed3 (patch) | |
tree | d223a8df722f237ce3d64e6da4f7a75f8958d394 | |
parent | 1400415c0c87248ad94cbfd3514fc6828cb92850 (diff) | |
download | qutebrowser-40477e826c9ec73a8f99177df645094be3ef5ed3.tar.gz qutebrowser-40477e826c9ec73a8f99177df645094be3ef5ed3.zip |
log: Handle JSONLogger in change_console_formatter
Fixes #6482
-rw-r--r-- | qutebrowser/utils/log.py | 14 | ||||
-rw-r--r-- | tests/end2end/test_invocations.py | 11 |
2 files changed, 20 insertions, 5 deletions
diff --git a/qutebrowser/utils/log.py b/qutebrowser/utils/log.py index b6f1f3e9b..2fb64eddd 100644 --- a/qutebrowser/utils/log.py +++ b/qutebrowser/utils/log.py @@ -363,12 +363,16 @@ def change_console_formatter(level: int) -> None: level: The numeric logging level """ assert console_handler is not None + old_formatter = console_handler.formatter - old_formatter = cast(ColoredFormatter, console_handler.formatter) - console_fmt = get_console_format(level) - console_formatter = ColoredFormatter(console_fmt, DATEFMT, '{', - use_colors=old_formatter.use_colors) - console_handler.setFormatter(console_formatter) + if isinstance(old_formatter, ColoredFormatter): + console_fmt = get_console_format(level) + console_formatter = ColoredFormatter( + console_fmt, DATEFMT, '{', use_colors=old_formatter.use_colors) + console_handler.setFormatter(console_formatter) + else: + # Same format for all levels + assert isinstance(old_formatter, JSONFormatter), old_formatter def qt_message_handler(msg_type: QtCore.QtMsgType, diff --git a/tests/end2end/test_invocations.py b/tests/end2end/test_invocations.py index 1ce22b7ea..076ebb2bd 100644 --- a/tests/end2end/test_invocations.py +++ b/tests/end2end/test_invocations.py @@ -743,3 +743,14 @@ def test_unavailable_backend(request, quteproc_new): message=('*qutebrowser tried to start with the Qt* backend but failed ' 'because * could not be imported.*')) line.expected = True + + +def test_json_logging_without_debug(request, quteproc_new): + args = _base_args(request.config) + ['--temp-basedir', ':quit'] + args.remove('--debug') + args.remove('about:blank') # interfers with :quit at the end + + quteproc_new.exit_expected = True + quteproc_new.start(args) + assert not quteproc_new.is_running() + assert not quteproc_new.captured_log |