gouge.uvicorn¶
Helpers for running gouge’s formatters under uvicorn.
This module is named uvicorn but never imports the uvicorn package (all
imports in gouge are absolute, so import uvicorn elsewhere still finds
the real one).
-
gouge.uvicorn.UVICORN_LOGGERS =
('uvicorn', 'uvicorn.error', 'uvicorn.access')¶ The loggers
capture_uvicorn()redirects by default.
-
gouge.uvicorn.capture_uvicorn(level=
None, loggers=('uvicorn', 'uvicorn.error', 'uvicorn.access'))¶ Route uvicorn’s log records through the root handlers.
uvicorn installs its own handlers on its loggers and stops them from propagating, so the formatter configured on the root logger (for example with
basicConfig()) never sees them. This removes the handlers of loggers and enables propagation. uvicorn is not imported.Call it after uvicorn configured its loggers, or uvicorn’s setup undoes it: either call it in a startup hook of the application (for example the FastAPI lifespan), or start uvicorn with
log_config=Noneso uvicorn does not install handlers in the first place (then only thepropagateflags matter). Note thataccess_log=Falsemakes uvicorn disable propagation ofuvicorn.access; calling this afterwards enables it again.