Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

To enable http level request/response logs in Application Server (AS), we can use the Access_Log_Valve which is provided in Tomcat 7. For more information, please go to http://tomcat.apache.org/tomcat-7.0-doc/config/valve.html#Access_Log_Valve.

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

...

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 request headers and  %{xxx}o stands for response headers.

Example 1: Logging request headers

Code Block
<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"/>

...

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.

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


Example 2: Logging response headers

Code Block
<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"/>

...

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

Example 3: Logging other variable values

Code Block
<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"/>

...

Code Block
“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. But, you can use ‘Extended Access Log Valve’ for this. Here only 2 parts (className and pattern) are modified from the previous configuration.

...

Now, when we send following POST request with URL encoded values param1=value1 and param2=value2,

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

The above configuration will log the following.

...