[GO] How to configure and use the Tomcat access log

Source: Internet
Author: User

Configure the location under Log for Server.xml, (Tomcat container)

<engine defaulthost= "localhost" name= "Catalina" >
<logger classname= "Org.apache.catalina.logger.FileLogger" prefix= "Localhost_log." suffix= ". txt" timestamp= "true "/>
<valve classname= "Org.apache.catalina.valves.AccessLogValve" filedateformat= "Yyyy-mm-dd" pattern= "%h%l%u%t%r%s %b%{referer}i%{user-agent}i%{x-jphone-uid}i%{x-up-subno}i "prefix=" Localhost_access_log. "suffix=". txt "directory = "/var/log/accesslog" condition= "Drop"/>
<context path= "" docbase= "cn_issue" debug= "0"/>
</Host>
<logger classname= "Org.apache.catalina.logger.FileLogger" prefix= "Catalina_log." suffix= ". txt" timestamp= "true" />
<realm classname= "Org.apache.catalina.realm.UserDatabaseRealm"/>
</Engine>

Here is the excerpt text

Original link:http://forum.ospod.com/post-25088-1.fhtml;jsessionid=3361f472a5e12b9b9bea1632ec50603a

Access log valve is used to create a log file in the same format as a standard Web server log file. Logs can be analyzed using the log Analysis tool to track page clicks, user session activity, and so on. Many of the configuration and behavior characteristics of Access log valve are the same as file logger, including automatic switching of log files nightly at midnight. Access log valve can be associated with any Catalina container and records all requests processed by that container.
Examples are as follows:

directory= "Logs" prefix= "Localhost_access_log." suffix= ". txt"
pattern= "%{x-forwarded-for-pound}i%l%u%t"%r "%s%b%t"%{http_x_up_calling_line_id}i ""%{x-up-calling-line-id}i ""%{ User-agent}i "" resolvehosts= "false"/>


ClassName The Java class name of the implementation. Must be set to Org.apache.catalina.valves.AccessLogValve.
Directory The directory where the log files are stored, either relative or absolute paths. If a relative path is used, it refers to the path relative to the $CATALINA _home. If you do not specify a directory property, the default value is "Logs" (relative to $CATALINA _home)
Pattern The format layout of the different information fields needs to be recorded for the request/response. If it is "common" or "combine", the standard format is selected. More information on configuring this property is available below.
Prefix The prefix of the log file name. If not specified, the default value is "Access_log." If you do not want to use a prefix, use a string of length 0.

Resolvehosts Set the IP address of the remote host to true by converting the DNS query to the host name. If False, the DNS query is ignored, and the IP address of the remote is reported.

Suffix The suffix of the log file name. If not specified, the default value is "". If you do not want to use a suffix, use a string of length 0.

Rotatable The default value is True, which is used to determine whether the log is flipped. If False, the log file is never flipped, and Filedataformat is ignored. Use sparingly.

Condition Open the condition log. If this property is set, the log will be created for the request only if Servletrequest.getattribute () is null. For example, if condition is set to junk, the request will only be logged if the Servlet.getattribute ("junk") ==null. With filters, you can easily set (or de-set) the properties of different requests.
Filedateformat Allows you to use a custom date format in the log file name. The format of the log also determines how often the log file is flipped. If you want to flip once every hour, set this value to Yyyy-mm-dd.hh


The Pattern property value is combined with the prefix "%" of the string constant and the pattern identifier. The pattern identifier is prefixed with "%" to replace the corresponding variable value in the current request/response. The following pattern is currently supported:

  • %a -Remote IP address
  • %A -Local IP address
  • %b -Number of bytes sent, excluding HTTP headers, if 0, use "-"
  • %B -Number of bytes sent, not including HTTP headers
  • %h -Remote host name (if resolvehost=false, remote IP address)
  • %H -Request Agreement
  • %l -The remote logical user name returned from Identd (Always return '-')
  • %m -Method of request (Get,post, etc.)
  • %p -Local port number to which the request was received
  • %q -query string (if present, to '? ') Start
  • %r -The first line of the request, containing the requested method and URI
  • %s -Status code of the response
  • %s -session ID of the user
  • %t -Log and time, using the usual log format
  • %u -remote user after authentication (if present, otherwise '-')
  • %u -URI path of the request
  • %v -Name of the local server
  • %d -the time, in milliseconds, to process the request
  • %T -the time, in seconds, to process the request

Examples of the results are as follows:
---[29/aug/2005:09:34:48 +0800] "get/waptest/server?productid=qqportal&actionid=index&user_type=1& Station=tencent&mid=12345678908888&mobile_no=13724179457&qazxcdew=1 HTTP/1.1 "404 710 0.015"-""-"" mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0) Opera 7.11 [ZH-CN] "

---[29/aug/2005:10:27:29 +0800] "options/http/1.1" 404 668 0.203 "-" "-" "microsoft-webdav-miniredir/5.1.2600"

Appendix:Server.xml

<?xml version= ' 1.0 ' encoding= ' utf-8 '?>
<Server>
<listener classname= "Org.apache.catalina.mbeans.ServerLifecycleListener"/>
<listener classname= "Org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
<GlobalNamingResources>
<environment name= "Simplevalue" type= "Java.lang.Integer" value= "/>"
<resource auth= "Container" description= "User database that can be updated and saved" name= "Userdatabase" type= "Org.apa Che.catalina.UserDatabase "/>
<resourceparams name= "Userdatabase" >
<parameter>
<name>factory</name>
<value>org.apache.catalina.users.MemoryUserDatabaseFactory</value>
</parameter>
<parameter>
<name>pathname</name>
<value>conf/tomcat-users.xml</value>
</parameter>
</ResourceParams>
</GlobalNamingResources>
<service name= "Catalina" >
<connector acceptcount= "connectiontimeout=" 20000 "disableuploadtimeout=" true "port=" "redirectport=" 8443 " >
</Connector>
<connector port= "8009" protocol= "ajp/1.3" protocolhandlerclassname= "Org.apache.jk.server.JkCoyoteHandler" redirectport= "8443" >
</Connector>
<engine defaulthost= "localhost" name= "Catalina" >
<logger classname= "Org.apache.catalina.logger.FileLogger" prefix= "Localhost_log." suffix= ". txt" timestamp= "true "/>
<valve classname= "Org.apache.catalina.valves.AccessLogValve" filedateformat= "Yyyy-mm-dd" pattern= "%h%l%u%t%r%s %b%{referer}i%{user-agent}i%{x-jphone-uid}i%{x-up-subno}i "prefix=" Localhost_access_log. "suffix=". txt "directory = "/log/accesslog" condition= "Drop"/>
<context path= "" docbase= "cn_issue" debug= "0"/>
</Host>
<logger classname= "Org.apache.catalina.logger.FileLogger" prefix= "Catalina_log." suffix= ". txt" timestamp= "true" />
<realm classname= "Org.apache.catalina.realm.UserDatabaseRealm"/>
</Engine>
</Service>
</Server>

[GO] How to configure and use the Tomcat access log

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.