Skip to content

Commit caa2b42

Browse files
committed
More log tweaking for config loading
1 parent 08a7a0b commit caa2b42

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

openeo_driver/config/load.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ def load_from_py_file(
3030
) -> Any:
3131
"""Load a config value from a Python file."""
3232
path = Path(path)
33-
_log.info(
34-
f"Loading configuration from Python file {path!r} (variable {variable!r})"
35-
)
33+
_log.debug(f"Loading configuration from Python file {path!r} (variable {variable!r})")
3634

3735
# Based on flask's Config.from_pyfile
3836
with path.open(mode="rb") as f:
@@ -73,11 +71,9 @@ def __call__(self, force_reload: bool = False) -> OpenEoBackendConfig:
7371
def get(self, force_reload: bool = False) -> OpenEoBackendConfig:
7472
"""Lazy load the config."""
7573
if self._config is None:
76-
_log.info("Lazy load config")
77-
self._config = self._load()
74+
self._config = self._load(reason="lazy_load")
7875
elif force_reload:
79-
_log.info("Force reload config")
80-
self._config = self._load()
76+
self._config = self._load(reason="force_reload")
8177

8278
return self._config
8379

@@ -87,13 +83,13 @@ def _default_config(self) -> ContextManager[Path]:
8783
"""
8884
return importlib_resources.path("openeo_driver.config", "default.py")
8985

90-
def _load(self) -> OpenEoBackendConfig:
86+
def _load(self, reason: Optional[str] = None) -> OpenEoBackendConfig:
9187
"""Load the config from config file."""
9288
with self._default_config() as default_config:
9389
config_path = os.environ.get(self.OPENEO_BACKEND_CONFIG) or default_config
9490
config = load_from_py_file(path=config_path, variable="config", expected_class=self.expected_class)
95-
if hasattr(config, "id"):
96-
_log.info(f"Loaded config {config.id=}")
91+
config_id = getattr(config, "id", None)
92+
_log.info(f"Loaded config {config_id=} from {config_path=} ({reason=})")
9793
return config
9894

9995
def flush(self):

0 commit comments

Comments
 (0)