Setting `log_level="debug"` doesn't output debug log messages on console
See original GitHub issueChecklist
- The bug is reproducible against the latest release and/or
master
. - There are no similar issues or pull requests to fix it yet.
Describe the bug
Using the latest uvicorn
version 0.13.3 and fastapi
version 0.63.0.
Bare minimum application to use logging:
import logging
from fastapi import FastAPI
app = FastAPI()
logger = logging.getLogger("foo")
@app.get("/")
def read_root():
logger.debug("hello")
return {"Hello": "World"}
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, port=8080, log_level="debug")
Output of running this file with python 3.8, and executing curl localhost:8080
in a separate terminal:
Press ENTER or type command to continue
INFO: Started server process [19618]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://127.0.0.1:8080 (Press CTRL+C to quit)
INFO: 127.0.0.1:48340 - "GET / HTTP/1.1" 200 OK
^CINFO: Shutting down
INFO: Waiting for application shutdown.
INFO: Application shutdown complete.
INFO: Finished server process [19618]
To reproduce
Run the code above.
Expected behavior
I expect to see debug log messages on the console.
Actual behavior
Debug log messages do not show up. logger.error()
messages do, but they are unformatted.
@app.get("/")
def read_root():
logger.error("hello")
return {"Hello": "World"}
produces:
INFO: Started server process [19731]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://127.0.0.1:8080 (Press CTRL+C to quit)
hello
INFO: 127.0.0.1:48342 - "GET / HTTP/1.1" 200 OK
Debugging material
Environment
Python 3.8.2, Ubuntu 16.04, uvicorn
version 0.13.3 and fastapi
version 0.63.0.
Additional context
None
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Logging HOWTO — Python 3.11.1 documentation
Display console output for ordinary usage of a command line script or program ... DEBUG:root:This message should go to the log file INFO:root:So...
Read more >c# - Why isn't Serilog writing Debug messages even when the ...
I was having this problem with a writer to MSSqlServer. The key in the answer is the ".MinimumLevel.Debug()" at the logger level in...
Read more >How to use Debug Log in Unity (without affecting performance)
The simplest way to print a message in the console in Unity is by using the Debug Log function, which takes a string...
Read more >Node.js Logging Tutorial - Stackify
Debug level can contain things like stack traces, input and output parameters, or special messages for developers.
Read more >console.debug() - Web APIs - MDN Web Docs
The console.debug() method outputs a message to the web console at the "debug" log level. The message is only displayed to the user...
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
That behavior seems wrong to me. I’d expect that at least passing
debug=True
/--debug
would enable more verbose logging for all loggers. Requiring a user to provide a log configuration file when they’re trying to get a simple application running is a big ask.config log of
logging
level.Setting the logging level of
uvicorn.run()
is different from that oflogging
module.This is execuate result: