configure_uvicorn_logging#

safir.logging.configure_uvicorn_logging(log_level=LogLevel.INFO)#

Set up logging.

This configures Uvicorn to use structlog for output formatting and installs a custom processor to parse its access log messages into additional log context that matches the format of Google log messages. This helps Google’s Cloud Logging system understand the logs. Access logs are sent to standard output and all other logs are sent to standard error.

Parameters:

log_level (LogLevel | str, default: <LogLevel.INFO: 'INFO'>) – The Python log level. May be given as a LogLevel enum (preferred) or a case-insensitive string.

Return type:

None

Notes

This method should normally be called during FastAPI app creation, either during Python module import or inside the function that creates and returns the FastAPI app that Uvicorn will run. This ensures the logging setup is complete before Uvicorn logs its first message.