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 the following XML xml element under the /Server/Service
/Engine/Host/
directory
element in the {WSO2AS_HOME}/
repositoryr
epository/conf/tomcat/catalina
-server.xml
file and and restart the AS server.
Code Block |
---|
<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"/> |
...
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.
Table of Contents
Example 1: Logging request headers
...
Code Block |
---|
text/plain; charset=utf-8 */* gzip,deflate,sdch |
Example 2: Logging response headers
The configuration is as follows:
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"/> |
The above will log Content-type
, Content-Length
, Date Date
and Server
headers of every response coming from AS, as follows:
...
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"/> |
The above will log the First 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)
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. However, you can use the Extended Access Log Valve
for this. Here only 2 parts ( className
and pattern
) are modified from the previous configuration.
...
Thereafter, when the POST request is sent together with the URL encoded values param1
=value1
and param2
=value2
:
Code Block |
---|
POST http://<IP>:<PORT>/example/servlets/servlet/RequestInfoExample |
...