summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2021-05-28 15:46:35 +0200
committerFlorian Bruhin <me@the-compiler.org>2021-05-28 15:54:56 +0200
commit98b4c80634f2415bfec9a02ceec643d80fc2622b (patch)
tree1a14261a4eb72a797dfad47e43da97224b5cd888
parent7afb9cfd7a8ad8581e88f16fd7db8f92c9e091ed (diff)
downloadqutebrowser-98b4c80634f2415bfec9a02ceec643d80fc2622b.tar.gz
qutebrowser-98b4c80634f2415bfec9a02ceec643d80fc2622b.zip
log: Handle JSONLogger in change_console_formatter
Fixes #6482 (cherry picked from commit 40477e826c9ec73a8f99177df645094be3ef5ed3)
-rw-r--r--qutebrowser/utils/log.py14
-rw-r--r--tests/end2end/test_invocations.py11
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