'Is it possible to add response time to uvicorn logs for FastApi?
My logger looks something like this:
log_config = {
"version": 1,
"disable_existing_loggers": True,
"formatters": {
"default": {
"()": "uvicorn.logging.DefaultFormatter",
"fmt": "%(asctime)s::%(levelname)s::%(name)s::%(filename)s::%(funcName)s::%(message)s",
"datefmt": "%Y-%m-%dT%H:%M:%S%z",
"use_colors": False,
},
"access": {
"()": "uvicorn.logging.AccessFormatter",
"datefmt": "%Y-%m-%dT%H:%M:%S%z",
"fmt": '%(asctime)s::%(levelprefix)s %(client_addr)s - "%(request_line)s" %(msecs)d %(status_code)s',
"use_colors": False,
},
},
"handlers":
{
"default":
{
"formatter": "default",
"class": 'logging.FileHandler',
"filename": CONFIG[SECTION]["default"]
},
"access":
{
"formatter": "access",
"class": 'logging.FileHandler',
"filename": CONFIG[SECTION]["access"]
},
},
"loggers":
{
"uvicorn": {"handlers": ["default"], "level": "INFO", "propagate": False},
"uvicorn.access": {"handlers": ["access"], "level": "INFO", "propagate": False},
}
}
Start config:
uvicorn.run(
app="app.main:app",
host="0.0.0.0",
port=8000,
reload=True,
log_config=log_config,
proxy_headers=True,
forwarded_allow_ips='*',
log_level="info"
)
In the access format, I dont see a way to add response time. I also cant seem to find a default list of params anywhere. How can I approach this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
