From 1f5684d74629a2c1f19d1852038e4915503d7c3e Mon Sep 17 00:00:00 2001 From: mizhexiaoxiao <1157861072@qq.com> Date: Fri, 18 Aug 2023 16:15:05 +0800 Subject: [PATCH] uvicorn add loggin config --- run.py | 2 +- run.sh | 3 --- uvicorn_loggin_config.json | 46 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 4 deletions(-) delete mode 100644 run.sh create mode 100644 uvicorn_loggin_config.json diff --git a/run.py b/run.py index f684449..03864e7 100644 --- a/run.py +++ b/run.py @@ -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") diff --git a/run.sh b/run.sh deleted file mode 100644 index a35e37a..0000000 --- a/run.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/zsh - -uvicorn app:app --reload --host 0.0.0.0 --port 9999 \ No newline at end of file diff --git a/uvicorn_loggin_config.json b/uvicorn_loggin_config.json new file mode 100644 index 0000000..72a2a9c --- /dev/null +++ b/uvicorn_loggin_config.json @@ -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 + } + } + } + \ No newline at end of file