How can I log request POST body in Flask? How can I log request POST body in Flask? flask flask

How can I log request POST body in Flask?


You can log additional info for each request with a Flask.before_request hook:

@app.before_requestdef log_request_info():    app.logger.debug('Headers: %s', request.headers)    app.logger.debug('Body: %s', request.get_data())


How about you create a small helper method, which you call in each and every controller of your flask application.

The helper method will be something like this:

def log_my_request_data(request_data):   #this method will log this data

and then in all controllers, get the request.data like this

from flask import requestrequest_data = request.data

and call log_my_request_data(request_data)