第一种情况,空的字段为“-”,是我想要的,只要不是“”就行,但是resp_body的双引号变成x22
# log_format
log_format main '"$remote_addr" "$remote_user" "$time_local" "$request" '
'"$status" "$body_bytes_sent" "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" "$request_time" '
'"$request_body" "$resp_body"';
#输出
"127.0.0.1" "-" "16/Jan/2019:11:24:05 +0800" "POST /test HTTP/1.1" "200" "20" "-" "curl/7.47.0" "-" "0.001" "-" "{\x22data\x22: \x22asasddsf\x22}"
第二种情况,resp_body没问题,但空字段是“”,我想要有默认值
# log_format
log_format main escape=none '"$remote_addr" "$remote_user" "$time_local" "$request" '
'"$status" "$body_bytes_sent" "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" "$request_time" '
'"$request_body" "$resp_body"';
#输出
"127.0.0.1" "" "16/Jan/2019:11:47:07 +0800" "POST /test HTTP/1.1" "200" "20" "" "curl/7.47.0" "" "0.002" "" "{"data": "asasddsf"}"
能不能在第一种情况下把引号输出正常,或第二种情况下把空字段输出默认值,如默认值为-,输出”-“
把源码src/http/modules/ngx_http_log_module.c修改了下当escape=none时空值返回-,重新编译了一下。但是感觉应该有更好当办法。