Default language.

Apache Tomcat valve logging


Apache Tomcat Valve logging helps to determine the following;

  • Whether an HTTP request is received by the Apache Tomcat server that hosts the  application. 
  • Header information. 

You can enable the Apache Tomcat valve logging from the server.xml file located in the Tomcat\conf\ folder.

To enable Apache Tomcat valve logging

  1. Search for the following entry in the server.xml file located in the <tomcat_install>/conf/ folder.
    <Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true" xmlNamespaceAware="false" xmlValidation="false">
  2. Check if the following Valve statement is available. Add the Valve statement if it is not available.

    <Valve className="org.apache.catalina.valves.
    FastCommonAccessLogValve"
    directory="logs" prefix="localhost_access_log." suffix=".log" pattern="%h %t  %u &quot;%r&quot; %s b:%b t:%D p:%F" resolveHosts="false" />

    Apache Tomcat version 7 or earlier

    <Valve className="org.apache.catalina.valves.
    FastCommonAccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".log" pattern="%h %t %u %{JSESSIONID}c &quot;%r&quot; %s b:%b t:%D p:%F" resolveHosts="false" />

    Apache Tomcat version 8 or later

    <Valve className="org.apache.catalina.valves.
    AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %t %u %{JSESSIONID}c &quot;%r&quot; %s b:%b t:%D p:%F " />

    This pattern captures the following details:

    • Client IP
    • Date and time of request
    • User name
    • JSESSIONID cookie sent with the request
    • Request
    • Status
    • Bytes sent
    • Total process time including transfer to browser in milliseconds
    • Process time excluding transfer in milliseconds
  3. Restart the Apache Tomcat server.

Each HTTP request is now logged in the localhost_access*.log file located in the <tomcat_install>\logs\ folder.

Pattern details

The following table describes the pattern details:

Pattern

Description

%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 resolve Hosts is false)

%H

Request protocol

%l

Remote logical username from identd (always returns '-')

%m

Request method (GET, POST)

%p

Local port on which this request was received

%q

Query string (appended 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 and transfer results to browser, in milliseconds

%F

Time taken to process the request, in milliseconds

%T

Time taken to process the request, in seconds

%I

Current request thread name (can compare later with stack traces)

%{xxx}i

write value of incoming header with name xxx  ex:  %{Cookie}i  will get you all the cookies sent

%{xxx}o

write value of outgoing header with name xxx

 %{xxx}c

write value of cookie with name xxx   ex: %{JSESSIONID}c

Examples

The following example illustrates the Valve statement to check Accept-Encoding headers.

<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".log" pattern="%t %m %r %s Encoding:%{Accept-Encoding}i" resolveHosts="false"/>

The following example illustrates the Valve statement to track the JSESSIONID cookie submitted with each request

<Valve className="org.apache.catalina.valves.AccessLogValve"
 directory="logs" prefix="localhost_access_log" suffix=".txt"
pattern="%h %t %u %{JSESSIONID}c &quot;%r&quot; %s " />

Related topic

Enabling-logs-for-Mid-Tier-troubleshooting

 

Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*