2019-12-25 tomcat日志变为json格式

2019-12-25  本文已影响0人  hopi

tomcat版本 7.0.79
1、修改tomcat的server.xml文件

配置文件139行 pattern 改为

    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
           prefix="localhost_access_log" suffix=".log"
           pattern="{&quot;client&quot;:&quot;%h&quot;,  &quot;client user&quot;:&quot;%l&quot;,   &quot;authenticated&quot;:&quot;%u&quot;,   &quot;access time&quot;:&quot;%t&quot;,     &quot;method&quot;:&quot;%r&quot;,   &quot;status&quot;:&quot;%s&quot;,  &quot;send bytes&quot;:&quot;%b&quot;,  &quot;Query?string&quot;:&quot;%q&quot;,  &quot;partner&quot;:&quot;%{Referer}i&quot;,  &quot;Agent version&quot;:&quot;%{User-Agent}i&quot;}"/>

2、取到的日志结果为:
{
"client": "192.168.1.222",
"client user": "-",
"authenticated": "-",
"access time": "[20/Aug/2018:14:44:41 +0800]",
"method": "HEAD / HTTP/1.1",
"status": "200",
"send bytes": "-",
"Query?string": "",
"partner": "-",
"Agent version": "curl/7.29.0"
}

上一篇下一篇

猜你喜欢

热点阅读