将非 2xx 请求的请求正文发送到 syslog nginx

问题描述

我有 Nginx 日志格式的这个配置

log_format graylog2_json escape=json '{ "timestamp": "$time_iso8601",'
                     '"remote_addr": "$remote_addr",'
                     '"remote_user": "$remote_user",'
                     '"body_bytes_sent": $body_bytes_sent,'
                     '"request_time": $request_time,'
                     '"status": $status,'
                     '"request": "$request",'
                     '"request_method": "$request_method",'
                     '"host": "$host",'
                     '"upstream_cache_status": "$upstream_cache_status",'
                     '"upstream_addr": "$upstream_addr",'
                     '"http_x_forwarded_for": "$http_x_forwarded_for",'
                     '"http_referrer": "$http_referer",'
                     '"http_user_agent": "$http_user_agent" }';


access_log syslog:server=<>,tag=<>,severity=info graylog2_json;
error_log syslog:server=<>,severity=error warn;

现在我想检查状态代码是否为非 2xx,然后将 request_body 添加到日志格式中。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)