将Flask 日志整合到Gunicorn日志并输出
Example Code
import logging
from flask import Flask, jsonify
app = Flask(__name__)
@app.route('/')
def index():
app.logger.debug('this is debug message')
app.logger.error('this is error message')
app.logger.critical('this is critical message')
return 'ok'
if __name__ != '__main__':
gunicorn_logger = logging.getLogger('gunicorn.error')
app.logger.handlers = gunicorn_logger.handlers
app.logger.setLevel(gunicorn_logger.level)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8000, debug=True)
Run:
gunicorn --workers=2 --bind=0.0.0.0:8000 --log-level=debug gunicorn_log:app