如何将我的应用程序参数添加到localhost_access_log。<date> .text file </date>

时间:2013-11-27 05:08:59

标签: tomcat log4j tomcat7 tomcat6

我的localhost_access_log..text文件在我的TOMCAT / logs中包含这样的日志数据 。 。

10.20.30.51 - - [22/Nov/2013:01:37:19 -0600] GET /myapp/static/css/third-party-css/images/ui-icons_2d6482_256x240.png HTTP/1.1 200 5355 https://10.20.30.60:8443/myapp/static/css/third-party-css/jquery-ui-1.8.19.custom.css Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0
10.20.30.52 - - [22/Nov/2013:01:37:20 -0600] POST /myapp/filter/getFilterPanelState HTTP/1.1 200 28 https://10.20.30.52:8443/myapp/pss/list Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0
10.20.30.53 - - [22/Nov/2013:01:37:22 -0600] GET /myapp/pss/discoveryVSOMData?_search=false&nd=1385105800099&rows=20&page=1&sidx=id&sord=desc HTTP/1.1 200 21 https://10.20.30.60:8443/myapp/pss/ Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0
10.20.30.51 - - [22/Nov/2013:01:38:20 -0600] GET /myapp/ HTTP/1.1 302 - - Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36

我想将userid,companyid ...以及其他一些与应用程序相关的字段添加到此日志中。对于每个新的日志行。

10.20.30.51 - - [22/Nov/2013:01:37:19 -0600] GET user1 company1 /myapp/static/css/third-party-css/images/ui-icons_2d6482_256x240.png HTTP/1.1 200 5355 https://10.20.30.60:8443/myapp/static/css/third-party-css/jquery-ui-1.8.19.custom.css Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0
10.20.30.52 - - [22/Nov/2013:01:37:20 -0600] POST user2 company2 /myapp/filter/getFilterPanelState HTTP/1.1 200 28 https://10.20.30.52:8443/myapp/pss/list Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0
10.20.30.53 - - [22/Nov/2013:01:37:22 -0600] GET user3 company3 /myapp/pss/discoveryVSOMData?_search=false&nd=1385105800099&rows=20&page=1&sidx=id&sord=desc HTTP/1.1 200 21 https://10.20.30.60:8443/myapp/pss/ Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0
10.20.30.51 - - [22/Nov/2013:01:38:20 -0600] GET user1 company1 /myapp/ HTTP/1.1 302 - - Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36

1 个答案:

答案 0 :(得分:0)

我做了

  1. 通过setAttribute()方法在我的请求中设置companyId

  2. 将%{companyId} r添加到

    patternpattern =“%h%l%u%t%{companyId} r%r%s%b%{Referer} i%{User-Agent} i”/&gt;

  3. 在tomcat / conf / server.xml

    现在正在工作:):)

      

    感谢Apache文档团队

    http://tomcat.apache.org/tomcat-6.0-doc/config/valve.html#Access_Log_Valve