uvicorn add loggin config

This commit is contained in:
mizhexiaoxiao 2023-08-18 16:15:05 +08:00
parent 267f18e18f
commit 1f5684d746
3 changed files with 47 additions and 4 deletions

2
run.py
View File

@ -1,4 +1,4 @@
import uvicorn
if __name__ == "__main__":
uvicorn.run("app:app", host="0.0.0.0", port=9999, reload=True)
uvicorn.run("app:app", host="0.0.0.0", port=9999, reload=True, log_config="uvicorn_loggin_config.json")

3
run.sh
View File

@ -1,3 +0,0 @@
#!/bin/zsh
uvicorn app:app --reload --host 0.0.0.0 --port 9999

View File

@ -0,0 +1,46 @@
{
"version": 1,
"disable_existing_loggers": false,
"formatters": {
"default": {
"()": "uvicorn.logging.DefaultFormatter",
"fmt": "%(levelprefix)s %(message)s",
"use_colors": null
},
"access": {
"()": "uvicorn.logging.AccessFormatter",
"fmt": "%(asctime)s - %(levelprefix)s %(client_addr)s - \"%(request_line)s\" %(status_code)s"
}
},
"handlers": {
"default": {
"formatter": "default",
"class": "logging.StreamHandler",
"stream": "ext://sys.stderr"
},
"access": {
"formatter": "access",
"class": "logging.StreamHandler",
"stream": "ext://sys.stdout"
}
},
"loggers": {
"uvicorn": {
"handlers": [
"default"
],
"level": "INFO"
},
"uvicorn.error": {
"level": "INFO"
},
"uvicorn.access": {
"handlers": [
"access"
],
"level": "INFO",
"propagate": false
}
}
}