来自:http://hi.baidu.com/gladfeel/blog/item/169e232a8c5d1b3c5343c1b0.html
配置http访问日志。Tomcat自带的能够记录的http访问日志很详细,取消下面这段的注释:
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="logs" prefix="localhost_access_log." suffix=".txt"
pattern="common" resolveHosts="false"/>
配置实例:
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="E:\Tomcat_log" prefix="longxun_tomcat." suffix=".txt"
pattern=''%h %l %u %t "%r" %s %b "%{Referer}i"''
resolveHosts="false" fileDateFormat="yyyy-MM-dd.HH"/>
其中: pattern="combined" 记录的日志内容更详细,也可以根据自己的需要定制。
fileDateFormat="yyyy-MM-dd.HH",会让日志文件按小时进行滚卷,比默认的按天滚卷要好些,尤其是访问量大的网站,可以考虑写成fileDateFormat="yyyy-MM-dd.HH.mm",就会是每分钟一个日志文件了。而且可以分别按Engine, Host, or Context,来记录自己的日志
生成的日志如:
202.108.1.15 - - [01/Aug/2007:13:35:41 8000] "POST /upload/upload.jsp?retUrl=60.99.88.122:8001&channelId=null&uploadPath=d:\\beijingnews/dnnchina\mmsource\images\2007\08\01&webroot=d:\&mulType=1&fileName=parent.document.form1.remark&filePath=parent.document.form1.MultimediaImgPath&fileSize=parent.document.form1.MultimediaSize&framename=parent.document.all.frmShow&waterPrint=0&position=1 HTTP/1.1" 200 458 "http://60.99.88.122:8001/longxun2/maincontrol/SSupLoadMultimedia?action=upLoadForm&showFlag=1&returl=60.99.88.122:8001&mulType=1&uploadName=&fileName=parent.document.form1.remark&filePath=parent.document.form1.MultimediaImgPath&fileSize=parent.document.form1.MultimediaSize&framename=parent.document.all.frmShow"
pattern参数具体含义:
Values for the pattern attribute are made up of literal text strings, combined with pattern identifiers prefixed by the "%" character to cause replacement by the corresponding variable value from the current request and response. The following pattern codes are supported:
%a - Remote IP address
%A - Local IP address
%b - Bytes sent, excluding HTTP headers, or ''-'' if zero
%B - Bytes sent, excluding HTTP headers
%h - Remote host name (or IP address if resolveHosts is false)
%H - Request protocol
%l - Remote logical username from identd (always returns ''-'')
%m - Request method (GET, POST, etc.)
%p - Local port on which this request was received
%q - Query string (prepended with a ''?'' if it exists)
%r - First line of the request (method and request URI)
%s - HTTP status code of the response
%S - User session ID
%t - Date and time, in Common Log Format
%u - Remote user that was authenticated (if any), else ''-''
%U - Requested URL path
%v - Local server name
%D - Time taken to process the request, in millis
%T - Time taken to process the request, in seconds
There is also support to write information from the cookie, incoming header, the Session or something else in the ServletRequest. It is modeled after the apache syntax:
%{xxx}i for incoming headers
%{xxx}c for a specific cookie
%{xxx}r xxx is an attribute in the ServletRequest
%{xxx}s xxx is an attribute in the HttpSession
The shorthand pattern name common (which is also the default) corresponds to %h %l %u %t "%r" %s %b".
The shorthand pattern name combined appends the values of the Referer and User-Agent headers, each in double quotes, to the common pattern described in the previous paragraph.
详情参考:
http://jakarta.apache.org/tomcat/tomcat-5.5-doc/config/valve.html
http://jakarta.apache.org/tomcat/tomcat-5.0-doc/config/logger.html
http://jakarta.apache.org/tomcat/tomcat-5.0-doc/config/host.html#Access%20Logs
而且还可以配合awstats来进行日志统计分析: http://www.chedong.com/tech/awstats.html http://blog.csdn.net/lizongbo/archive/2005/02/18/291929.aspx
联系客服