---
title: "💭 logs with FastAPI and Uvicorn · Issue #1508 · tiangolo/fastapi"
description: "!https://github.com/tiangolo/fastapi/issues/1508"
date: 2023-12-15
published: true
tags:
  - python
  - fastapi
  - webdev
  - thought
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)
```

!!! note

    This post is a <a href="/thoughts/" class="wikilink" data-title="Thoughts" data-description="These are generally my thoughts on a web page or some sort of url, except a rare few don&#39;t have a link. These are dual published off of my..." data-date="2024-04-01">thought</a>. It's a short note that I make
    about someone else's content online <a href="/tags/thoughts/" class="hashtag-tag" data-tag="thoughts" data-count=2 data-reading-time=3 data-reading-time-text="3 minutes">#thoughts</a>
