From 5a0497a087f9fda0883930d1beda537a540ba73b Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Sun, 17 May 2020 07:01:06 -0400 Subject: 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. --- tests/unit/utils/test_log.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'tests/unit/utils/test_log.py') 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.""" -- cgit v1.2.3-54-g00ecf