I have an api.py file with the following:
from fastapi import FastAPI
import logging
import uvicorn
app = FastAPI(title="api")
LOG = logging.getLogger(__name__)
LOG.info("API is starting up")
LOG.info(uvicorn.Config.asgi_version)
@app.get("/")
async def get_index():
LOG.info("GET /"
return {"Hello": "Api"}
The application locally is run with:
uvicorn api:app --reload
INFO: Will watch for changes in these directories: ['/Users/user/code/backend/api']
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: Started reloader process [44258] using StatReload
INFO: Started server process [44260]
INFO: Waiting for application startup.
INFO: Application startup complete.
It is not logging any of the startup messages.
Later on when sending a http request to the api:
INFO: 127.0.0.1:50538 - "POST /api/v1/endpoint HTTP/1.1" 200 OK
In the function body there is LOG.info("example") that does not get logged either.
Is there a way to make FastAPI logging work with Uvicorn and also in production (independently of the execution environments like Uvicorn).