Closed vstrimaitis closed 3 years ago
@vstrimaitis took a quick crunch, let me know if this working for you. Released 1.4.0rc for this. see doc here for more information: https://github.com/bobbui/json-logging-python#26-custom-log-formatter
After taking a quick look at the change it seems like this should indeed help, thanks! From the examples it's not entirely clear how I'd be able to access that request_info
object in a custom formatter, but I can look into that in more detail on my own.
@vstrimaitis This is a simpler way to get the response object and do whatever u want with it https://github.com/bobbui/json-logging-python/blob/1.4.0rc1/example/custom_log_format_request.py#L17
@vstrimaitis This is a simpler way to get the response object and do whatever u want with it https://github.com/bobbui/json-logging-python/blob/1.4.0rc1/example/custom_log_format_request.py#L17
Looks great, thanks for the help!
Just a heads up for someone reading, here's a solution for getting the request/response body itself —
class CustomRequestJSONLog(json_logging.JSONRequestLogFormatter):
"""
Customized logger
"""
def _format_log_object(self, record, request_util):
request = record.request_response_data._request
response = record.request_response_data._response
json_log_object = super(
CustomRequestJSONLog, self)._format_log_object(
record, request_util)
json_log_object.update({
"request_body": request.data.decode(),
"response_body": response.data.decode()
})
return json_log_object
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:
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!