美文网首页
2019-12-25 tomcat日志变为json格式

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

作者: hopi | 来源:发表于2019-12-25 10:26 被阅读0次

    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"
    }

    相关文章

      网友评论

          本文标题:2019-12-25 tomcat日志变为json格式

          本文链接:https://www.haomeiwen.com/subject/imaqoctx.html