Hi, I am using Kong 0.13 CE, I am trying to capture request body and response body for debugging purposes. So far I have managed to capture request body but not response body.
This is what I have tried so far, the lines commented out are one of the 2 ways that I have tested:
log_format log_req_resp escape=json '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" $request_time req_body:"$request_body" resp_body:"$resp_body"';
server {
server_name kong;
> for i = 1, #proxy_listeners do
listen $(proxy_listeners[i].listener);
> end
error_page 400 404 408 411 412 413 414 417 494 /kong_error_handler;
error_page 500 502 503 504 /kong_error_handler;
# access_log ${{PROXY_ACCESS_LOG}} postdata;
access_log ${{PROXY_ACCESS_LOG}} log_req_resp;
error_log ${{PROXY_ERROR_LOG}} ${{LOG_LEVEL}};
lua_need_request_body on;
set $resp_body "";
# body_filter_by_lua '
# local resp_body = string.sub(ngx.arg[1], 1, 1000)
# ngx.ctx.buffered = (ngx.ctx.buffered or "") .. resp_body
# if ngx.arg[2] then
# ngx.var.resp_body = ngx.ctx.buffered
# end
# ';
body_filter_by_lua 'ngx.log(ngx.ERR, ngx.var.resp_body, ngx.var.request_body )';
Any ideas why I always get null resp_body?
Thanks!