FastAPI gunicorn添加日志时间戳

问题描述 投票:0回答:1

我使用docker来运行FastAPI。https:/fastapi.tiangolo.comdeployment

tiangolo/uvicorn-gunicorn-fastapi:python3.7

start.sh的样子。

exec gunicorn -k uvicorn.workers.UvicornWorker -c "$GUNICORN_CONF" "$APP_MODULE"

我的docker日志看起来没有时间戳 My docker log looks like without timestamps:

INFO:     123.123.123.123:48736 - "GET /wp-login.php HTTP/1.0" 404 Not Found
INFO:     123.123.123.123:48808 - "GET /robots.txt HTTP/1.0" 404 Not Found
INFO:     123.123.123.123:48810 - "GET / HTTP/1.0" 200 OK

它看起来是这样的 gunicorn_conf.py 它使用

use_loglevel = os.getenv("LOG_LEVEL", "info")

如何轻松优雅地修改INFO和ERROR的日志格式与时间戳?

docker logging gunicorn fastapi
1个回答
1
投票

您应该可以使用以下命令修改访问日志的格式 access_log_format 在你 gunicorn_conf.py 文件。你可以根据你的 gunicorn_conf.py 档案 这个 uvicorn-gunicorn docker镜像中使用。

© www.soinside.com 2019 - 2024. All rights reserved.