tomcat日志格式转化为json

一、将tomcat的访问日志转化为json格式
1、修改tomcat的server.xml文件

        "org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".log"
               pattern="{"client":"%h",  "client user":"%l",   "authenticated":"%u",   "access time":"%t",     "method":"%r",   "status":"%s",  "send bytes":"%b",  "Query?string":"%q",  "partner":"%{Referer}i",  "Agent version":"%{User-Agent}i"}"/>
#以上配置文件在135行

2、取到的日志结果为:

{"client":"192.168.1.222",  "client user":"-",   "authenticated":"-",   "access time":"[20/Aug/2018:15:14:17 +0800]",     "method":"HEAD / HTTP/1.1",   "status":"200",  "send bytes":"-",  "Query?string":"",  "partner":"-",  "Agent version":"curl/7.29.0"}
{"client":"192.168.1.108",  "client user":"-",   "authenticated":"-",   "access time":"[20/Aug/2018:15:14:19 +0800]",     "method":"HEAD / HTTP/1.1",   "status":"200",  "send bytes":"-",  "Query?string":"",  "partner":"-",  "Agent version":"curl/7.29.0"}
{"client":"192.168.1.109",  "client user":"-",   "authenticated":"-",   "access time":"[20/Aug/2018:15:16:20 +0800]",     "method":"HEAD / HTTP/1.1",   "status":"200",  "send bytes":"-",  "Query?string":"",  "partner":"-",  "Agent version":"curl/7.29.0"}

3、输入的json格式为:

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

你可能感兴趣的:(运维)