馃挱 logs with FastAPI and Uvicorn 路 Issue #1508 路 tiangolo/fastapi ================================================================ !https://github.com/tiangolo/fastapi/issues/1508 Date: December 15, 2023 logs with FastAPI and Uvicorn 路 Issue #1508 路 fastapi/fastapi Hello, Thanks for FastAPI, easy to use in my Python projects ! However, I have an issue with logs. In my Python project, I use : app = FastAPI() uvicorn.run(app, host="0.0.0.0", port=8000) And when... GitHub 路 github.com [1] Setting an additional log handler to the uvicorn logger for access logs in fastapi was not straightforward, but This post was very helpful. ``` @app.on_event("startup") async def startup_event(): logger = logging.getLogger("uvicorn.access") handler = logging.StreamHandler() handler.setFormatter(logging.Formatter("%(asctime)s - %(levelname)s - %(message)s")) logger.addHandler(handler) ``` !!! note This post is a thought [2]. It's a short note that I make about someone else's content online #thoughts [3] References: [1]: https://github.com/tiangolo/fastapi/issues/1508 [2]: /thoughts/ [3]: /tags/thoughts/