-
-
Notifications
You must be signed in to change notification settings - Fork 761
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uvicorn adds a logging handler to the root logger #630
Comments
This bit me as well in Delgan/loguru#247 trying to get all logs handled by loguru. It started with some logs from the |
stchris
added a commit
to stchris/uvicorn
that referenced
this issue
May 15, 2020
Overriding the root logger is probably not intended here. See discussion in encode#630
tomchristie
pushed a commit
that referenced
this issue
May 15, 2020
Overriding the root logger is probably not intended here. See discussion in #630
I posted a solution to intercept everything (gunicorn/uvicorn/httpx/etc.) here, hope this helps the next ones who want to do the same thing 🙂 |
closed by #674 |
1 task
cr313
added a commit
to cr313/py-project-uvicorn
that referenced
this issue
Apr 19, 2024
Overriding the root logger is probably not intended here. See discussion in encode/uvicorn#630
Kludex
pushed a commit
to Kludex/jik
that referenced
this issue
Aug 14, 2024
Overriding the root logger is probably not intended here. See discussion in encode/uvicorn#630
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When using the default config, unicorn adds an handler to the root logger:
https://github.com/encode/uvicorn/blob/master/uvicorn/config.py#L86
Since all loggers in python are propagated back to the root logger, this means that all logs from all loggers will reach the handler Uvloop adds
When I create a custom logger in my app all my log messages are printed twice, once from my handlers, and then from the uvicorn handler on the root logger.
Since uvicorn always use "uvicorn.*" loggers, I was able to create a new "unicorn" logger and move the handler to it on app startup
I'm not sure if its the intended functionality, it was kinda unexpected for me.
If you wish to fix it, It can be easily fixed by changing "" to "uvicorn" in
https://github.com/encode/uvicorn/blob/master/uvicorn/config.py#L86
But doing so will break the existing functionality for users that currently just use logging without any config and it works for them.
The text was updated successfully, but these errors were encountered: