修改源码来修改nginx的日志格式
看到第一处:static u_char cached_http_log_iso8601
;
更改1:
;
=》
;
看到第二处:
ngx_cached_http_log_iso8601.len =>
更改2:
ngx_cached_http_log_iso8601.len =>
=》
ngx_cached_http_log_iso8601.len => 看到第三处:
p3 = &cached_http_log_iso8601;
(void) ngx_sprintf(p3, "%4d-%02d-%02dT%02d:%02d:%02d%c%02d:%02d",
tm.ngx_tm_year, tm.ngx_tm_mon,
tm.ngx_tm_mday, tm.ngx_tm_hour,
tm.ngx_tm_min, tm.ngx_tm_sec,
tp->gmtoff < 0 ? '-' : '+',
ngx_abs(tp->gmtoff / 60), ngx_abs(tp->gmtoff % 60));
更改3:
(void) ngx_sprintf(p3, "%4d-%02d-%02dT%02d:%02d:%02d%c%02d:%02d",
tm.ngx_tm_year, tm.ngx_tm_mon,
tm.ngx_tm_mday, tm.ngx_tm_hour,
tm.ngx_tm_min, tm.ngx_tm_sec,
tp->gmtoff < 0 ? '-' : '+',
ngx_abs(tp->gmtoff / 60), ngx_abs(tp->gmtoff % 60));
=》
(void) ngx_sprintf(p3, "%4d-%02d-%02d %02d:%02d:%02d",
tm.ngx_tm_year, tm.ngx_tm_mon,
tm.ngx_tm_mday, tm.ngx_tm_hour,
tm.ngx_tm_min, tm.ngx_tm_sec);
ok,修改好之后,重新编译
再把accesslog的日志格式定义为
log_formatmain'$remote_addr - $time_iso8601 [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
访问,查看日志内容:
192.168.3.170 - 2013-08-05 11:50:01 "GET /favicon.ico HTTP/1.1" 404 581 "-" "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.1 (KHTML, like Gecko) Maxthon/4.0.6.2000 Chrome/26.0.1410.43 Safari/537.1" "-"
ok,搞定
页:
[1]