This documentation is for WSO2 Application Server version 5.1.0. View documentation for the latest release.

Unknown macro: {next_previous_link3}
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 14 Current »

To enable http level request/response logs in Application Server (AS), we can use the Access_Log_Valve which is provided in Tomcat 7. 

To enable logging, you have to put following xml element under  /Server/Service/Engine/Host/ element in  {WSO2AS_HOME}/repository/conf/tomcat/catalina-server.xml and restart the AS server.

<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="${carbon.home}/repository/logs"
prefix="localhost_access_log_sample."
suffix=".log"
pattern="%{xxx}i %{xxx}o"
resolveHosts="false"/>

This will create a log file named localhost_access_log_sample.{DATE}.log  inside the  {WSO2AS_HOME}/repository/logs directory.

The  pattern  parameter is used to specify which parts of the request/response needs to be logged. In the above sample, xxx stands for the header name we need to log. Here %{xxx}i stands for the request headers and  %{xxx}o stands  for the response headers.


Example 1: Logging request headers

The configuration is as follows:

<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="${carbon.home}/repository/logs"
prefix="localhost_access_log_test."
suffix=".log"
pattern="%{Content-Type}i %{Accept}i %{Accept-Encoding}i"
resolveHosts="false"/>

This will log the  Content-type, Accept and Accept-encoding headers of every request coming to AS.

For an example, here we are going to use the  RequestInfoExample that comes with AS, to send the request to.

When we send the following http request:

GET http://<IP>:<PORT>/example/servlets/servlet/RequestInfoExample?abc=xyz

We can see the following log entry in the  localhost_access_log_sample.{DATE}.log  file.

text/plain; charset=utf-8        */*        gzip,deflate,sdch

Example 2: Logging response headers

The configuration is as follows:

<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="${carbon.home}/repository/logs"
prefix="localhost_access_log_test."
suffix=".log"
pattern="%{Content-Type}o %{Content-Length}o %{Date}o %{Server}o"
resolveHosts="false"/>

The above will log Content-type, Content-Length, Date and Server headers of every response coming from AS, as follows:

text/html;charset=ISO-8859-1       662       Tue, 09 Jul 2013 11:21:50 GMT        WSO2 Carbon

Example 3: Logging other variable values

The configuration is as follows:

<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="${carbon.home}/repository/logs"
prefix="localhost_access_log_test."
suffix=".log"
pattern="%r %q %h"
resolveHosts="false"/>

The above will log the first line of the request (method and request URI), Query string (prepended with a '?' if it exists) and Remote hostname (or IP) of every request coming to AS as follows. (For more information on all possible values that can be given in the  pattern parameter, go to http://tomcat.apache.org/tomcat-7.0-doc/config/valve.html#Access_Log_Valve)

“GET /example/servlets/servlet/RequestInfoExample?abc=xyz HTTP/1.1”      ?abc=xyz     10.100.0.67

Example 4: Logging URL encoded parameters

You can not use the Access Log Valve to log URL encoded parameters. However, you can use the Extended Access Log Valve for this. Here only 2 parts ( className and pattern ) are modified from the previous configuration.

The configuration is as follows:

<Valve className="org.apache.catalina.valves.ExtendedAccessLogValve" 
directory="${carbon.home}/repository/logs"
prefix="localhost_access_log_extended."
suffix=".log"
pattern="x-P(param1) x-P(param2)"
resolveHosts="false"/>

Thereafter, when the POST request is sent together with the URL  encoded values  param1=value1  and  param2=value2:

POST http://<IP>:<PORT>/example/servlets/servlet/RequestInfoExample

The  above configuration will log the following:

'value1'     'value2'
  • No labels