Tomcat's access log settings and storage log path modifications

Source: Internet
Author: User
Tags documentation session id port number

In Tomcat, access log is not set by default. Configure the following in the Server.xml file.

[HTML] view plain copy print?               <!--Access log processes all example. Documentation at:/docs/config/valve.html-<!--<valve Classname= "org.apache.catalina.valves . Accesslogvalve "directory=" Logs "prefix=" Localhost_access_log. "suffix=". txt "pattern=" common "resolveho Sts= "false"/>--
In general, Tomcat and Apache are used together, and Apache also has access log. TOMCA also set the words are not superfluous.

One advantage of access log in Tomcat is that the session ID is also printed. Depending on the session ID, you have the following convenience.

1, you can track a user's screen operation according to the session ID.

2, if an error occurs, it can be reproduced according to the session ID. Easy to find out where the error is.


Settings are very simple.

[HTML] view plain copy print?               <!--Access log processes all example. Documentation at:/docs/config/valve.html---<valve classname= "Org.apache.catalina.valves.AccessLogValve" directory= "Logs" prefix= "Localhost_access_log." suffix= ". Log" pattern= "common" resolvehosts= "false"/>

Access Log in tomcat is stored by default in the logs directory. This directory is going to get bigger, and if the traffic is large, the hard drive will soon be jammed.


There are two ways to resolve this:

Do not log access log: Comment out the <Valve> configuration item in Server.xml to store access log somewhere else, and then periodically compress the archive: Modify the "Server.xml" in the <Valve> configuration item in the Directory parameter, change to another path in the large hard disk

If it's a running system, take a few more steps, stop Tomcat, remove the existing access log file from the Tomcat/logs, modify the configuration file, and then restart Tomcat. An example of a specific modification is as follows:

Assuming the new storage path is/opt/logs/access_logs, the filename prefix is modified to Xjj_access_log to avoid confusion with other tomcat logs: Cd/opt/logs mkdir access_logs vim/opt/app/ Tomcat-xjj/conf/server.xml Modify: directory= "/opt/logs/access_logs" Modify: prefix= "Xjj_access_log" Stop tomcat:/opt/app/ Tomcat-xjj/bin/shutdown.sh cannot be stopped. Kill: Kill-9 <pid> cd/opt/app/tomcat-xjj/logs
Rename Localhost_access_log xjj_access_log *.txt (use suffix. txt to filter out all Access log files and batch rename) MV *.txt/opt/logs/access_logs/restart T omcat:/opt/app/tomcat-xjj/bin/startup.sh

Then, if necessary, write another script to periodically compress the files in the archive/opt/logs/access_logs (steps).
Attached

Pattern
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


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.