Wie konfigurieren Sie die Fastapi -Protokollierung so, dass sie sowohl mit Uvicorn lokal als auch in der Produktion funkPython

Python-Programme
Guest
 Wie konfigurieren Sie die Fastapi -Protokollierung so, dass sie sowohl mit Uvicorn lokal als auch in der Produktion funk

Post by Guest »

Ich habe die folgende Fastapi-Anwendung: < /p>

Code: Select all

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"}
< /code>
Die Anwendung lokal wird mit: < /p>
 ausgeführt.uvicorn api:app --reload
< /code>
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.
< /code>
protokolliert keine der Startmeldungen. Später beim Senden einer HTTP-Anfrage an die API: < /p>
INFO:     127.0.0.1:50538 - "POST /api/v1/endpoint HTTP/1.1" 200 OK
In der Funktionskörper befindet sich log.info ("Beispiel") , das auch nicht protokolliert wird. Gibt es eine Möglichkeit, Fastapi -Protokollierung mit Uvicorn und auch in Produktion (unabhängig von den Ausführungsumgebungen wie Uvicorn) zu machen?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post