]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
manager: better logging for config validation
authorAleš Mrázek <ales.mrazek@nic.cz>
Thu, 27 Jul 2023 11:51:27 +0000 (13:51 +0200)
committerAleš Mrázek <ales.mrazek@nic.cz>
Thu, 27 Jul 2023 12:39:37 +0000 (12:39 +0000)
manager/knot_resolver_manager/server.py
manager/knot_resolver_manager/utils/modeling/exceptions.py

index 6803f5c2dbcb6e15616c3719b8a98c081330f095..345a3f8a934a6805191f3c7525598d4746fd024c 100644 (file)
@@ -363,7 +363,7 @@ async def _load_raw_config(config: Union[Path, Dict[str, Any]]) -> Dict[str, Any
                 f"Manager is configured to load config file at {config} on startup, but the file does not exist."
             )
         else:
-            logger.info("Loading initial configuration from %s", config)
+            logger.info(f"Loading configuration from '{config}' file.")
             config = try_to_parse(await readfile(config))
 
     # validate the initial configuration
@@ -372,7 +372,6 @@ async def _load_raw_config(config: Union[Path, Dict[str, Any]]) -> Dict[str, Any
 
 
 async def _load_config(config: Dict[str, Any]) -> KresConfig:
-    logger.info("Validating initial configuration...")
     config_validated = KresConfig(config)
     return config_validated
 
@@ -409,7 +408,7 @@ async def _deny_working_directory_changes(config_old: KresConfig, config_new: Kr
 def _set_working_directory(config_raw: Dict[str, Any]) -> None:
     rundir = get_rundir_without_validation(config_raw)
 
-    logger.info("changing working directory to rundir at '%s'", rundir.to_path().absolute())
+    logger.debug(f"Changing working directory to '{rundir.to_path().absolute()}'.")
     os.chdir(rundir.to_path())
 
 
index 34d25b876932066bfacdc00c5b2440f4f921eba7..c2a28817e0b4c04437aca87e414756fd356a9b4d 100644 (file)
@@ -27,11 +27,18 @@ class DataValidationError(DataModelingBaseException):
         return self._tree_path
 
     def msg(self):
-        return f"[{self.where()}] " + super().__str__()
+        return f"[{self.where()}] {super().__str__()}"
 
     def recursive_msg(self, indentation_level: int = 0) -> str:
+        msg_parts: List[str] = []
+
+        if indentation_level == 0:
+            indentation_level += 1
+            msg_parts.append("Configuration validation error detected:")
+
         INDENT = indentation_level * "\t"
-        msg_parts: List[str] = [f"{INDENT}{self.msg()}"]
+        msg_parts.append(f"{INDENT}{self.msg()}")
+
         for c in self._child_exceptions:
             msg_parts.append(c.recursive_msg(indentation_level + 1))
         return "\n".join(msg_parts)
@@ -49,7 +56,7 @@ class AggregateDataValidationError(DataValidationError):
         msg_parts: List[str] = []
         if indentation_level == 0:
             inc = 1
-            msg_parts.append("multiple configuration errors detected:")
+            msg_parts.append("Configuration validation errors detected:")
 
         for c in self._child_exceptions:
             msg_parts.append(c.recursive_msg(indentation_level + inc))