-
-
Notifications
You must be signed in to change notification settings - Fork 60
Add support for logging the response body #68
Copy link
Copy link
Closed
Description
I'm using Flask and would like to extend the current request logs to include the request and response bodies. This is what I've attempted so far:
from flask import request
class RequestFormatter(json_logging.JSONLogWebFormatter):
def _format_log_object(
self, record: logging.LogRecord, request_util: json_logging.util.RequestUtil
):
log_obj = super()._format_log_object(record, request_util)
log_obj.update({
"request_body": request.get_data(as_text=True),
"response_body": "???"
})
return log_obj
# ...
json_logging.init_request_instrument(app=app, custom_formatter=RequestFormatter)I can't find a way of getting the response body without some dirty hacks (e.g. monkey patching FlaskAppRequestInstrumentationConfigurator). Am I missing something or is this feature not implemented? Thanks!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels