Skip to content

Commit 2af625e

Browse files
committed
feat: Reconfigure uvicorn loggers and reapply polling log filter during lifespan setup
1 parent 9ce55a5 commit 2af625e

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

middleware/api/src/middleware/api/api/fastapi_app.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,14 @@ def __init__(self, app_config: Config) -> None:
168168

169169
logger.debug("API configuration: %s", self._config.model_dump())
170170

171-
# Apply polling log filter to uvicorn access logger
172-
logging.getLogger("uvicorn.access").addFilter(PollingLogFilter())
173-
174171
@asynccontextmanager
175172
async def lifespan(_app: FastAPI) -> AsyncGenerator[None, None]:
173+
# Re-apply our log format after uvicorn has finished its own log setup.
174+
# uvicorn.main() installs its own handlers on uvicorn.access/uvicorn.error
175+
# *after* this module is imported, so we must reconfigure here.
176+
_configure_uvicorn_loggers(self._config.log_level)
177+
logging.getLogger("uvicorn.access").addFilter(PollingLogFilter())
178+
176179
# Initialize business logic and its stores
177180
try:
178181
try:

0 commit comments

Comments
 (0)