From 580bface5e22bbc3af7febd09d1008683bf5acd6 Mon Sep 17 00:00:00 2001 From: Julius Scheuerer <95489434+JuliusScheuerer@users.noreply.github.com> Date: Wed, 25 Mar 2026 20:40:05 +0100 Subject: [PATCH] Move configure_logging() from module level to lifespan Importing the app module no longer triggers logging configuration as a side effect. Logging is now configured inside the lifespan context manager, before the analyzer engine loads. structlog loggers are lazy and work correctly before configuration. --- src/document_anonymizer/api/app.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/document_anonymizer/api/app.py b/src/document_anonymizer/api/app.py index ce48f03..fba7b6a 100644 --- a/src/document_anonymizer/api/app.py +++ b/src/document_anonymizer/api/app.py @@ -16,7 +16,6 @@ from document_anonymizer.security.rate_limiter import RateLimiterMiddleware from document_anonymizer.web.routes import web_router -configure_logging() logger = structlog.get_logger(__name__) _VERSION = importlib.metadata.version("document-anonymizer") @@ -24,7 +23,9 @@ @asynccontextmanager async def lifespan(app: FastAPI) -> AsyncIterator[None]: # noqa: ARG001 - """Eagerly load the analyzer engine on startup to fail fast.""" + """Configure logging and eagerly load the analyzer engine on startup.""" + configure_logging() + from document_anonymizer.api.dependencies import get_analyzer logger.info("startup", action="loading_analyzer_engine")