How can I customize a JSON request log formatter?
buildpeak opened this issue · 4 comments
From this example (https://github.com/bobbui/json-logging-python/blob/master/example/custom_log_format.py), I can easily customize a JSON non-web formatter.
However, it seems not easy to customize a JSON log fomatter dealing with request information. For example, like this:
request = record.request_info.request
request_adapter = request_util.request_adapter
json_log_object = {
...
"request_id": request_util.get_correlation_id(request),
"path": request_adapter.get_path(request),
...
}
Because, request_util
is not passed to logging.Formatter.format
method. Any idea?
Thanks
u should use init_request_instrument to pass a customized custom formatter for request logging, see the method signature here . I've just updated readme to include new example for web logging https://github.com/bobbui/json-logging-python#26-custom-log-formatter
u should use init_request_instrument to pass a customized custom formatter for request logging, see the method signature here . I've just updated readme to include new example for web logging https://github.com/bobbui/json-logging-python#26-custom-log-formatter
Thanks, but the problem is that I need to get an instance of request_util
in my custom formatter so that I can get an instance of a request adapter.
@buildpeak After tackle this #68 , I think the better way to customize JSON logging request is something like that
main.zip
Note: the log file cannot be written using filter