Nginx定义日志
定义日志格式
未修改前
- 定义的日志格式
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log main;
- 生成的日志
修改后
- 定义的日志格式
log_format access_json escape=json '{ \"remoteAddr\": \"$remote_addr\", \"remoteUser\": \"$remote_user\", \"requestId\" : \"$request_id\", \"timeIso\": \"$time_iso8601\", \"request\": \"$request\", \"requestMethod\": \"$request_method\", \"requestTime\": $request_time, \"status\": \"$status\" \"uri\": \"$uri\", \"requestLength\": $request_length, \"httpReferer\": \"$http_referer\", \"httpForwarded\": \"$http_x_forwarded_for\" }';
access_log logs/access.log access_json;
- 生成的日志
- 取第一行日志解析为Json展示