Comments (3)
Can you give an MRE on which the change will benefit you?
from uvicorn.
Hey, see here an example:
import uvicorn
async def app(scope, receive, send):
assert scope['type'] == 'http'
await send({
'type': 'http.response.start',
'status': 200,
'headers': [
[b'content-type', b'text/plain'],
],
})
await send({
'type': 'http.response.body',
'body': b'Hello, world!',
})
if __name__ == "__main__":
LOG_CONFIG = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"simple": {
"format": "[%(levelname)s] %(message)s",
},
},
"handlers": {
"stdout": {
"level": "NOTSET",
"class": "logging.StreamHandler",
"formatter": "simple",
"stream": "ext://sys.stdout",
}
},
"root": {
"handlers": ["stdout"],
"level": "WARNING",
},
"loggers": {
"uvicorn": {
"handlers": ["stdout"],
"level": "INFO",
"propagate": False,
},
},
}
uvicorn.run("main:app", log_config=LOG_CONFIG)
I'm setting uvicorn
logger to log on level INFO
, so every child logger (uvicorn.error
, uvicorn.access
, uvicorn.asgi
, etc) will use that (unless something specific is declared for them). What this means is that no message logged by MessageLoggerMiddleware
will be printed to stdout because they are logged at created level TRACE (5).
So the thing is that even having this config, uvicorn will still load the MessageLoggerMiddleware
because I have not passed explicitly the log_level
parameter. I think that "the need" of passing the log_level
parameter along with the log_config
(or having to declare the child logger levels explicitly in the log_config
) is an unexpected behavior that leads to execute MessageLoggerMiddleware
without needing it.
Checking getEffectiveLevel()
will return the "real final" level that the logger will log in. So that's why I'm suggesting to change logger.level
to logger.getEffectiveLevel()
here.
Hope this helps to understand it. If this is still not clear, let me know.
from uvicorn.
Got it. Thanks. Do you mind creating a PR for it? 🙏
from uvicorn.
Related Issues (20)
- reload doesn't work from programmatic launch (asyncio)
- 16,000 simultaneous request with 16 workers HOT 3
- `--reload-include` doesn't work with hidden files e.g. `--reload-include .env` HOT 1
- ContextVars pollution when uvicorn installed without [standard] extensions HOT 2
- asyncio.exceptions.CancelledError with asyncio HOT 4
- Error: [WinError 10054] An existing connection was forcibly closed by the remote host
- WebSockets and --max-requests does not reload Workers HOT 5
- Add support for Fowarded header (RFC 7239) HOT 3
- uvicorn may respond to requests sent after the client asks for the connection to be closed HOT 11
- Django, uvicorn, gunicorn inside docker HOT 1
- await request.is_disconnected() brings up large ClientDisconnected error in Uvicorn v0.28.0 HOT 7
- WebSocket does not complete coroutine after disconnection HOT 2
- The service process always interrupts abnormally after certain requests
- Child Processes Not Terminating with Uvicorn 0.29.0 HOT 7
- Requirement typo? typing_extensions>=4.0 HOT 1
- Unexcepted behavior while reloading HOT 13
- https://uvicorn.org/ should redirect to https://www.uvicorn.org/ HOT 1
- Unable to get the transport ssl context from the request. This prevents checking the Client provided certificate and matching up the provided CN against allowed users/server.
- Should server shutdown after receiving "lifespan.shutdown.failed"? HOT 6
- `uvicorn.run` `env_file` Not Passed Correctly
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from uvicorn.