from flask import request
from flask import Flask, jsonify
import logging
import logging.config
import time
logger = logging.getLogger()
logger.setLevel(logging.INFO)
rq = time.strftime('%Y%m%d%H%M', time.localtime(time.time()))
logfile = "logging.log"
#logging.basicConfig(level=logging.DEBUG,
#    format='[%(asctime)s] %(levelname)s [%(funcName)s: %(filename)s, %(lineno)d] %(message)s',
#    datefmt='%Y-%m-%d %H:%M:%S',
#    filemode='a')


fh = logging.FileHandler(logfile, mode='w')
fh.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s")
fh.setFormatter(formatter)
logger.addHandler(fh)


app = Flask(__name__)


@app.route('/webhook', methods=['POST'])
def webhook_task():
    logger.info('body:%s',request.get_data())
    return "OK",200


if __name__ == '__main__':
    app.run(host="0.0.0.0",debug=True)


参考:
1、https://www.cnblogs.com/vovlie/p/4178077.html
2、https://www.cnblogs.com/CJOKER/p/8295272.html
3、https://stackoverflow.com/questions/31637774/how-can-i-log-request-post-body-in-flask
09-26 17:26