问题描述
我们面临一个问题,即我们需要记录每次调用的请求正文,而不管其失败或成功。 我能够记录状态代码 200 而不是其他的请求正文(使用 Openresty Web 服务器)
log_format detailed_log_format escape=json '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" "$http_x_forwarded_for" Request : "$request_body" Response : "$response_body"'
'Auth-header : "$http_auth" User : "$custom"'
'rt=$request_time urt="$upstream_response_time"';
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.response_body = ngx.ctx.buffered
end
';
access_log /var/log/Nginx/access.log detailed_log_format buffer=1 if=$loggable;
127.0.0.1 - [02/Apr/2021:11:52:51 +0530] "POST /example/api/ HTTP/1.1" 200 675 "https://example.com/test" "Mozilla/5.0 (X11; Linux x86_64) 苹果 WebKit/537.36 (KHTML,like Gecko) Chrome/xxx Safari/xx" "" Request : "{\"answer\":{\"n\":\"six\"}}"响应:“”身份验证头:“”用户:“”rt=0.235 urt="0.236"
没有记录 4xx 状态代码的请求正文:
127.0.0.1 - - [06/Apr/2021:17:23:04 +0530] "POST /example/api/ HTTP/1.1" 403 0.000 71 "https://example.com/test" "Mozilla /5.0 (X11; Linux x86_64) AppleWebKit/537.36 Chrome/xxx Safari/xxx" "-"用户:"-"
我找不到任何与登录状态代码相关的文档。我怀疑这是否可能,或者是否有任何其他方式可以使用 Lua 块或其他任何东西来完成?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)