]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
manager/logging.py: added NOTICE level docs-logging-noti-c8sowa/deployments/7479
authorAleš Mrázek <ales.mrazek@nic.cz>
Tue, 26 Aug 2025 09:03:24 +0000 (11:03 +0200)
committerAleš Mrázek <ales.mrazek@nic.cz>
Tue, 26 Aug 2025 09:46:27 +0000 (11:46 +0200)
For now, only the level has been added, not the logger. To avoid confusion in the mapping, where notice(config) was mapped to warning (python).

python/knot_resolver/manager/logging.py

index 39d0c6bf84ccc885bab38c35e3d6140ecc96a170..6ad52966f8605cf984f0b38f85023cb4fe06e3b8 100644 (file)
@@ -12,6 +12,27 @@ from .constants import LOGGING_LEVEL_STARTUP
 
 logger = logging.getLogger(__name__)
 
+NOTICE_LEVEL = (logging.WARNING + logging.INFO) // 2
+NOTICE_NAME = "NOTICE"
+
+_config_to_level = {
+    "crit": logging.CRITICAL,
+    "err": logging.ERROR,
+    "warning": logging.WARNING,
+    "notice": NOTICE_LEVEL,
+    "info": logging.INFO,
+    "debug": logging.DEBUG,
+}
+
+_level_to_name = {
+    logging.CRITICAL: "CRITICAL",
+    logging.ERROR: "ERROR",
+    logging.WARNING: "WARNING",
+    NOTICE_LEVEL: NOTICE_NAME,
+    logging.INFO: "INFO",
+    logging.DEBUG: "DEBUG",
+}
+
 
 def get_log_format(config: KresConfig) -> str:
     """
@@ -33,24 +54,15 @@ def get_log_format(config: KresConfig) -> str:
 
 
 async def _set_log_level(config: KresConfig) -> None:
-    levels_map = {
-        "crit": "CRITICAL",
-        "err": "ERROR",
-        "warning": "WARNING",
-        "notice": "WARNING",
-        "info": "INFO",
-        "debug": "DEBUG",
-    }
-
     # when logging group is set to make us log with DEBUG
     if config.logging.groups and "manager" in config.logging.groups:
-        target = "DEBUG"
+        target = logging.DEBUG
     # otherwise, follow the standard log level
     else:
-        target = levels_map[config.logging.level]
+        target = _config_to_level[config.logging.level]
 
     # expect exactly one existing log handler on the root
-    logger.warning(f"Changing logging level to '{target}'")
+    logger.warning(f"Changing logging level to '{_level_to_name[target]}'")
     logging.getLogger().setLevel(target)