Tomcat Access log configuration, logging Post request parameters

Source: Internet
Author: User
Tags tomcat

First, configuration and description

Tomcat access log format configuration, under the host tag in Config/server.xml Plus

<valve classname= "Org.apache.catalina.valves.AccessLogValve" directory= "Logs"
prefix= "Localhost_access_log" suffix= ". txt"
pattern= "%h%l%u%t &quot;%r&quot; [%{postdata}r]%s%{referer}i%{user-agent}i%T%b "/>

We will see the following text in the log file:

10.217.14.16--[21/oct/2016:15:48:54 +0800] "Post/updates/related_notice_num.json http/1.0" [Channel=app Store& gid=92391918-2173-4a66-8b31-b2fb3f8fb3df&os=2&plat=2&sver=10.000000&token= MZM1OTC0MJQ1MKB3ZWLIBY55BXGUY29TFHDLAWJVFDQ5ZGFMMJK0YJQ5YWQXMTZIZJBMYWM4ZDDHYZG3ZWQ0&UA=&VER=4.2.1] 200 -allapp/4.2.1 (IPhone; IOS 10.0.2; scale/3.00) 0.004 91


Parameter description:

ClassName The official document says: This must is set to Org.apache.catalina.valves.AccessLogValve to use the default access log valve.
Directory directory where log files are stored. Usually set to the logs file that is already in Tomcat.
Prefix The name prefix of the log file.
Suffix The name suffix of the log file.
Pattern The most important parameter. The following will be said in detail.
Resolvehosts If it is true,tomcat, the server IP address is converted to the hostname via DNS, and if False, the server IP address is written directly. False by default.
Rotatable The default True,tomcat generated file name is prefix (prefix) +.+ time (typically by day) +.+suffix (suffix), such as: Localhost_access_log.2007-09-22.txt. If set to False, Tomcat ignores the time, does not generate a new file, and the file name is: Localhost_access_log.txt. This log file will be super large.
Condition This parameter is not very practical, can set any value, such as set to Condition= "TKQ", then only when Servletrequest.getattribute ("TKQ") is empty, the log will be recorded.

Filedateformat
As the name implies, it is the time format. However, this time format works for the log file name. The full name of the log file we generated: Localhost_access_log.2016-09-22.txt, that was the 2016-09-22. If you want Tomcat to generate a log file every hour, it is also very simple, set this value to: filedateformat= "yyyy-mm-dd.hh", of course, can also be generated by the minute, you change it ^_^

Below is the emphasis on pattern. It has more parameters. Can be set into common,combined two formats.

Value of common:%h%l%u%t%r%s%b
Combined value:%h%l%u%t%r%s%b%{referer}i%{user-agent}i (as for the last two values of combined why, I'm not sure)

[html]  View Plain  copy%a    This is the record visitor's IP, in the log is 127.0.0.1  %a    This is the IP of the ground server, in the log is 192.168.254.108  %b    send information bytes, not including the HTTP header, if the number of bytes is 0, displayed as-  % b    the number of bytes to send information, excluding HTTP headers.   %h    The name of the server. If Resolvehosts is false, here is the IP address, for example, my log is 10.217.14.16  %h    Visitor's agreement, here is http/1.0   %l    official explanation:remote logical username from identd  ( Possible translation: Record the name provided by the browser for authentication) (always returns  '-')   %m    access method, is get or post   %p    locally received ports    %q    For example, if you're visiting AAA.JSP?BBB=CCC, this is where it's shown? bbb= CCC, is the meaning of QueryString   %r   first line of the request  (method  and request uri)   The requested method and the url  %s   http response status code    %s     User's session id, this session&nbspID You can also check the detailed explanation, each time will generate a different session id  %t    request time   %u     has been authenticated by the visitor, otherwise is "-"   %u    access URL address, I here is/rightmainima/leftbott4.swf  %v     Server name, maybe that's what you wrote in the URL, I'm localhost  %d   time taken to  process the request,in millis, the time consumed by the request, in milliseconds   %t   time taken  to process the request,in seconds, request consumption time, in seconds    attached: Reference Official document:  http:// Tomcat.apache.org/tomcat-5.5-doc/config/valve.html


Second, configure the print post parameters

In addition, the%r parameter can print out the requested URL and get parameters. If the URL specifies that the access method is Post,post, the parameter is not printed. What to do if you need to print the post parameters.

It is noted that I have the opening example of the%{postdata}r in valve configuration. Yes, the PATTERRN of this combined format can be implemented. But it's not enough to configure this stuff in valve. Because PostData gives us a custom parameter name. You need to set this value in Request. The code that sets PostData to request is attached below.

[java]  View plain  copy package com.xiaoxiliu      import  java.io.ioexception;   import java.util.enumeration;      import  javax.servlet.filter;   import javax.servlet.filterchain;   import  javax.servlet.filterconfig;   import javax.servlet.servletexception;   import  javax.servlet.servletrequest;   import javax.servlet.servletresponse;      import org.slf4j.logger;   import org.slf4j.loggerfactory;      Public  final class PostDataDumperFilter implements Filter {  

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.