From: Aleš Mrázek Date: Thu, 27 Jul 2023 11:51:27 +0000 (+0200) Subject: manager: better logging for config validation X-Git-Tag: v6.0.2~25^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=de33b64b58fbae121716b98afc4478e0da7749fb;p=thirdparty%2Fknot-resolver.git manager: better logging for config validation --- diff --git a/manager/knot_resolver_manager/server.py b/manager/knot_resolver_manager/server.py index 6803f5c2d..345a3f8a9 100644 --- a/manager/knot_resolver_manager/server.py +++ b/manager/knot_resolver_manager/server.py @@ -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()) diff --git a/manager/knot_resolver_manager/utils/modeling/exceptions.py b/manager/knot_resolver_manager/utils/modeling/exceptions.py index 34d25b876..c2a28817e 100644 --- a/manager/knot_resolver_manager/utils/modeling/exceptions.py +++ b/manager/knot_resolver_manager/utils/modeling/exceptions.py @@ -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))