nginx日志json格式化

cat nginx.conf


log_format log_json '{ "@timestamp": "$time_local", '
    '"remote_addr": "$remote_addr", '
    '"referer": "$http_referer", '
    '"request": "$request", '
    '"status": $status, '
    '"bytes": $body_bytes_sent, '
    '"agent": "$http_user_agent", '
    '"x_forwarded": "$http_x_forwarded_for", '
    '"up_addr": "$upstream_addr",'
    '"up_host": "$upstream_http_host",'
    '"up_resp_time": "$upstream_response_time",'
    '"request_time": "$request_time"'
    ' }';
tail -f access.log



{ "@timestamp": "19/Apr/2019:10:10:51 +0800", "remote_addr": "47.***.***.225", "referer": "https://www.1iwl.com/archives/265/", "request": "GET /archives/265/ HTTP/1.1", "status": 200, "bytes": 6366, "agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36", "x_forwarded": "-", "up_addr": "*.*.*.*:9000","up_host": "-","up_resp_time": "0.028","request_time": "0.028" }

QQ截图20190419101218.png

from:https://blog.csdn.net/lihao21/article/details/78784895

添加新评论