Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_log_level_name() fetches wrong key from QgsSettings #84

Open
kannes opened this issue Aug 16, 2024 · 0 comments
Open

get_log_level_name() fetches wrong key from QgsSettings #84

kannes opened this issue Aug 16, 2024 · 0 comments

Comments

@kannes
Copy link

kannes commented Aug 16, 2024

get_log_level_name seems to try to load from QGIS3.ini which is undocumented and broken:

It uses get_log_level_key(target)
which uses setting_key("log_level", target.id)
which ends up prepending the plugin name to the key, and passes that to get_setting() without overriding the internal=True parameter
which ends up generating and requesting the key /PLUGINNAME//PLUGINNAME/log_level/foo_log_target.

Instead it should request /PLUGINNAME/log_level/foo_log_target

Fixed by generating the key as f"log_level/{target.id}" and skipping the get_log_level_key function completely:

diff --git a/test/conftest.py b/test/conftest.py
index eeadbd7..764206d 100644
--- a/test/conftest.py
+++ b/test/conftest.py
@@ -13,7 +13,6 @@ import pytest
 from ..testing.utilities import TestTaskRunner
 from ..tools.custom_logging import (
     LogTarget,
-    get_log_level_key,
     setup_logger,
     teardown_logger,
 )
@@ -23,7 +22,7 @@ from ..tools.settings import set_setting
 
 @pytest.fixture(scope="session")
 def initialize_logger(qgis_iface):
-    set_setting(get_log_level_key(LogTarget.FILE), "NOTSET")
+    set_setting(f"log_level/{LogTarget.FILE}", "NOTSET")
     setup_logger(plugin_name(), qgis_iface)
     yield
     teardown_logger(plugin_name())
diff --git a/tools/custom_logging.py b/tools/custom_logging.py
index 489f4b5..4fbe530 100644
--- a/tools/custom_logging.py
+++ b/tools/custom_logging.py
@@ -239,14 +239,9 @@ def add_logging_handler_once(logger: logging.Logger, handler: logging.Handler) -
     return True
 
 
-def get_log_level_key(target: LogTarget) -> str:
-    """Finds QSetting key for log level"""
-    return setting_key("log_level", target.id)
-
-
 def get_log_level_name(target: LogTarget) -> str:
     """Finds the log level name of the target"""
-    return get_setting(get_log_level_key(target), target.default_level, str)
+    return get_setting(f"log_level/{target.id}", target.default_level, str)

Not sure if this is a proper fix as this behaviour is not documented and I did not end up using or testing it any further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant