---
title: "logs with FastAPI and Uvicorn · Issue #1508 · tiangolo/fastapi"
description: "!https://github.com/tiangolo/fastapi/issues/1508"
date: 2023-12-16
published: true
tags:
  - dev
  - fastapi
  - python
  - thought
  - webdev
template: link
---


<div class="embed-card embed-card-external">
  <a href="https://github.com/tiangolo/fastapi/issues/1508" class="embed-card-link" target="_blank" rel="noopener noreferrer">
    <div class="embed-card-image">
      <img src="https://opengraph.githubassets.com/3626b55a49f478ae7777a024404b93ac7a2a79e40db37973cf0cee8113e76d2e/fastapi/fastapi/issues/1508" alt="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=&#34;0.0.0.0&#34;, port=8000) And when..." loading="lazy">
    </div>
    <div class="embed-card-content">
      <div class="embed-card-title">logs with FastAPI and Uvicorn · Issue #1508 · fastapi/fastapi</div>
      <div class="embed-card-description">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=&#34;0.0.0.0&#34;, port=8000) And when...</div>
      <div class="embed-card-meta">GitHub &middot; github.com</div>
    </div>
  </a>
</div>


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)
```
