Tengine 用了好久了,就是偶尔查看日志的时候觉得会比较麻烦,最近几天优化了下日志格式,觉得优化后在阅读方面还是比较直观的,而且也添加了一些功能。例如(upstream_addr,upstream_status,request_time,upstream_response_time)等信息。当然,我这是测试环境,并没有配置 upstream 反向代理。那相同的配置,查看线上的日志就会出现所需的一些信息了。
下面来看一下更改前与更改后的一些对比:
注意:测试所刷出的 log 都是通过本机的 chrome 浏览器,访问同一站点所生成的
旧的格式:
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
旧的日志输出:
[root@docker-100 conf]# tail -f ../logs/access.log
10.1.0.105 - - [24/Jan/2016:22:21:27 +0800] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36" "-"
10.1.0.105 - - [24/Jan/2016:22:21:27 +0800] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36" "-"
10.1.0.105 - - [24/Jan/2016:22:21:27 +0800] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36" "-"
10.1.0.105 - - [24/Jan/2016:22:21:27 +0800] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36" "-"
10.1.0.105 - - [24/Jan/2016:22:21:28 +0800] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36" "-"
新的格式:
log_format main '$remote_addr|$time_local|$request|'
'$status|$body_bytes_sent|$http_referer|'
'$http_user_agent|$http_x_forwarded_for|'
'$upstream_addr|$upstream_status|$request_time|$upstream_response_time';
新的日志输出:
[root@docker-100 logs]# tail -f access.log
10.1.0.105|24/Jan/2016:22:20:21 +0800|GET / HTTP/1.1|304|0|-|Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36|-|-|-|0.000|-
10.1.0.105|24/Jan/2016:22:20:21 +0800|GET / HTTP/1.1|304|0|-|Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36|-|-|-|0.000|-
10.1.0.105|24/Jan/2016:22:20:22 +0800|GET / HTTP/1.1|304|0|-|Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36|-|-|-|0.000|-
10.1.0.105|24/Jan/2016:22:20:22 +0800|GET / HTTP/1.1|304|0|-|Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36|-|-|-|0.000|-
10.1.0.105|24/Jan/2016:22:20:22 +0800|GET / HTTP/1.1|304|0|-|Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36|-|-|-|0.000|-