为了能够访问Flask API
内的AWS CloudWatch Logs
日志,我向Flask
应用添加了以下配置:
from logging.config import dictConfig
# loggings
dictConfig( {
'version': 1,
'formatters': {'default': {
'format': '[%(asctime)s] %(levelname)s in %(module)s: %(message)s',
}},
'handlers': {
'wsgi': {
'class': 'logging.StreamHandler',
'stream': 'ext://sys.stdout',
'formatter': 'default'
}
},
'root': {
'level': 'INFO',
'handlers': ['wsgi']
}
} )
Flask App部署在Nginx server
上。在nginx
上一直有效,直到我在其后添加Gunicorn
为止,因为我无法同时发出多个请求:
gunicorn -b 0.0.0.0:5000 --workers=5 api:app
但是在添加Gunicorn
之后,我不再在CloudWatch Logs
中获得应用程序的日志,这就是我得到的:
[2018-10-04 12:48:25 +0000] [7] [INFO] Starting gunicorn 19.9.0
12:48:25
[2018-10-04 12:48:25 +0000] [7] [INFO] Listening at: http://0.0.0.0:5000 (7)
12:48:25
[2018-10-04 12:48:25 +0000] [7] [INFO] Using worker: sync
12:48:25
[2018-10-04 12:48:25 +0000] [10] [INFO] Booting worker with pid: 10
12:48:25
[2018-10-04 12:48:25 +0000] [11] [INFO] Booting worker with pid: 11
12:48:25
[2018-10-04 12:48:25 +0000] [12] [INFO] Booting worker with pid: 12
12:48:25
[2018-10-04 12:48:25 +0000] [13] [INFO] Booting worker with pid: 13
12:48:25
[2018-10-04 12:48:25 +0000] [14] [INFO] Booting worker with pid: 14
我的问题是:如何将应用程序日志重定向到Gunicorn
?
答案 0 :(得分:0)
https://medium.com/@trstringer/logging-flask-and-gunicorn-the-manageable-way-2e6f0b8beb2f
默认情况下,将Gunicorn日志设置为警告。因此,您需要检查并更新Gunicorn级别。