diff options
author | Ryan Roden-Corrent <ryan@rcorre.net> | 2020-05-17 07:01:06 -0400 |
---|---|---|
committer | Ryan Roden-Corrent <ryan@rcorre.net> | 2020-05-17 17:37:45 -0400 |
commit | 5a0497a087f9fda0883930d1beda537a540ba73b (patch) | |
tree | c8d22da67bdde2722f91cc9bf8f7efdfcd963ca4 /tests/unit/utils/test_log.py | |
parent | 305e7c96d5e2fdb3b248b27dfb21042fb2b7e0b8 (diff) | |
download | qutebrowser-5a0497a087f9fda0883930d1beda537a540ba73b.tar.gz qutebrowser-5a0497a087f9fda0883930d1beda537a540ba73b.zip |
Add loglevel config settings.
Log levels can now be configured in config.py by setting
loggin.level.console (for stdout/stderr) and logging.level.ram (for
:messages).
This is of interest for users who would like password-manager
integration that uses `fake-key` to send sensitive strings to websites.
The default 'debug' ram logging would store various logs containing the
sensitive data.
Previously the loglevel was only configurable through CLI flags, and
those only affected the console loglevel. We felt a config value would
be nicer than just adding another flag for RAM loglevel, requiring you
to create an alias for qutebrowser and ensure _that_ alias gets used
anywhere qutebrowser might be invoked.
Logging is initialized before the config is loaded, so configuration-set
loglevels have to be loaded in a second, later stage. However, this
stage will only set the console loglevel if it wasn't set on the CLI, as
a CLI flag feels like a more explicit action that should override a
config.
Fixes #5286.
Diffstat (limited to 'tests/unit/utils/test_log.py')
-rw-r--r-- | tests/unit/utils/test_log.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/unit/utils/test_log.py b/tests/unit/utils/test_log.py index a74d81600..45543a136 100644 --- a/tests/unit/utils/test_log.py +++ b/tests/unit/utils/test_log.py @@ -255,6 +255,30 @@ class TestInitLog: warnings.warn("test warning", PendingDeprecationWarning) +@pytest.mark.parametrize( + 'console_cli,console_conf,console_expected,ram_conf,ram_expected', + [ + (None, None, logging.INFO, None, logging.NOTSET), + (None, None, logging.INFO, 'CRITICAL', logging.CRITICAL), + (None, 'WARNING', logging.WARNING, 'INFO', logging.INFO), + ('INFO', 'WARNING', logging.INFO, 'VDEBUG', logging.VDEBUG), + ('WARNING', 'INFO', logging.WARNING, 'CRITICAL', logging.CRITICAL), + ]) +def test_init_from_config(mocker, console_cli, console_conf, console_expected, + ram_conf, ram_expected): + args = argparse.Namespace(debug=False, loglevel=console_cli, color=True, + loglines=10, logfilter="", force_color=False, + json_logging=False, debug_flags=set()) + log.init_log(args) + + conf = mocker.Mock() + conf.logging.level.ram = ram_conf + conf.logging.level.console = console_conf + log.init_from_config(conf) + assert log.ram_handler.level == ram_expected + assert log.console_handler.level == console_expected + + class TestHideQtWarning: """Tests for hide_qt_warning/QtWarningFilter.""" |