Duplicate logs when use logging.basicConfig in application
See original GitHub issueChecklist
- The bug is reproducible against the latest release or
master
. - There are no similar issues or pull requests to fix it yet.
Describe the bug
When use logging.basicConfig to config logging in application, uvicorn logs will duplicate in console.
Steps to reproduce the bug
app.py:
import logging
from fastapi import FastAPI
logging.basicConfig(level=logging.INFO)
app = FastAPI(debug=True)
run it:
uvicorn app:app
Expected behavior
expect no duplicate logs.
Actual behavior
uvicorn.error logs duplicated:
INFO: Started server process [85610]
INFO:uvicorn.error:Started server process [85610]
INFO: Waiting for application startup.
INFO:uvicorn.error:Waiting for application startup.
INFO: Application startup complete.
INFO:uvicorn.error:Application startup complete.
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO:uvicorn.error:Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
Debugging material
I think the uvicorn logger should not propagate, because it already handled by uvicorn handler. And the behavior of gunicorn is no duplicate logs.
Add "propagate": False
to https://github.com/encode/uvicorn/blob/master/uvicorn/config.py#L107 can fix the issue.
"uvicorn": {"handlers": ["default"], "level": "INFO", "propagate": False},
Environment
Running uvicorn 0.15.0 with CPython 3.9.7 on Darwin
Additional context
Maybe related: https://github.com/encode/uvicorn/issues/614
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Duplicate logs when calling logging.basicConfig
Problem: When I call logging.basicConfig in addition to configuring my own logger, I get duplicate logs · I'm running python 3.6.8 · Easy...
Read more >Logging HOWTO — Python 3.11.1 documentation
To log variable data, use a format string for the event description message and append the variable data as arguments. For example: import...
Read more >A Step-by-Step Guide to Python Logging
A comprehensive guide to understanding the advantages and usage of Python Logging module.
Read more >Python Logging Basics - The Ultimate Guide To Logging
The module provides a way for applications to configure different log handlers and a ... a utility function called basicConfig that handles most...
Read more >Python Logging Guide - Best Practices and Hands-on ...
Logging with Django and uWSGI: To deploy web applications you can use StreamHandler as logger which sends all logs to For Django you...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Any Update on this one? It’s really annoying 😦
@matthew-viglione My workaround in the meantime has been: