webmachine access post body in *_perf_logger

72 Views Asked by At

Attempting to intercept all the requests on webmachine API. I took a copy of webmachine_perf_logger.erl and changed to publish the {verb, resource, module}.

For the posts I'm also interested in BODY. Because the logging part in webmachine_decision_core.erl gets triggered in a different process

 respond(Code) ->
      ....
      spawn(fun() -> do_log(LogData) end),

I do not see how can I access the it.

Is there any way to access it or other alternative is appreciated.

1

There are 1 best solutions below

4
On

Have you experimented with the finish_request resource function (https://github.com/basho/webmachine/wiki/Resource-Functions#resource-functions)? Like any other resource function it receives the request data and a context. You could do something like:

finish_request(ReqData, Context) ->
    do_log(extract_log_data(ReqData, Context)),
    {true, ReqData, Context}.

This would log whatever you extract from request data and context for every request. Note that crashed requests might not call finish_request.