问题描述
为了能够访问AWS CloudWatch Logs
的Flask API
AWS CloudWatch Logs
,我向Flask
App添加了以下配置:
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
。
直到我在其后添加Gunicorn
为止,在nginx
都可以正常工作,因为我无法同时发出多个请求:
gunicorn -b 0.0.0.0:5000 --workers=5 api:app
但是在添加Gunicorn
,我不再在CloudWatch Logs
中获得应用程序的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
?
1楼
默认情况下,gunicorn日志设置为警告。 因此,您需要检查并更新Gunicorn水平。