怎么将日志打印到文件
在main.py加入log_config=“./uvicorn_config.json”
import uvicornif __name__ == "__main__":uvicorn.run("app:app", host="0.0.0.0", port=8000, log_config="./uvicorn_config.json")
uvicorn_config.json
{"version": 1,"disable_existing_loggers": false,"formatters": {"default": {"()": "uvicorn.logging.DefaultFormatter","fmt": "%(asctime) s - %(levelprefix) s %(message) 3","use_colors": null},"aссеss": {"()": "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": ["ассеss"],"level": "INFO","propagate": false}}}
}