![](/img/trans.png)
[英]Flask raises `Address already in use` running with a WSGI server such as Gunicorn
[英]Log requests to a flask server using gunicorn as wsgi server … to AWS cloudwatch
我正在使用帶有gunicorn的燒瓶服務器作為wsgi服務器。
我想將所有請求詳細信息記錄到cloudwatch。
from flask import Flask, jsonify, request
app = Flask(__name__)
@app.route('/')
def index():
return jsonify({
'logging': "I want to log this request to cloudwatch",
"request": request
})
if __name__=='__main__':
app.run()
一種設置記錄器並使用watch望塔的方法
https://watchtower.readthedocs.io/en/latest/#example-flask-logging-with-watchtower
import watchtower, flask, logging
logging.basicConfig(level=logging.INFO)
app = flask.Flask("loggable")
handler = watchtower.CloudWatchLogHandler()
app.logger.addHandler(handler)
logging.getLogger("werkzeug").addHandler(handler)
@app.route('/')
def index():
logging.info("I want to log this request to cloudwatch")
return jsonify({
"request": request
})
if __name__ == '__main__':
app.run()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.