To enable http level request/response logs in WSO2AS, we can use Access_Log_Valve [1] 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.
This will create a log file named “localhost_access_log_sample.{DATE}.log” inside {WSO2AS_HOME}/repository/logs directory.
Here, ‘pattern’ parameter is the one we can use to specify which parts of the request/response needs to be logged. In above sample, xxx stands for the header name we need to log. Here %{xxx}i stands for request headers and %{xxx}o for response headers.
Example 1: Logging request headers
This will log Content-type, Accept and Accept-encoding headers of every request coming to AS.
For an example, here we are going to use RequestInfoExample which comes with AS, to send the request to.
When we send following http request,
we can see following log entry in “localhost_access_log_sample.{DATE}.log” file.
text/plain; charset=utf-8 */* gzip,deflate,sdch
Example 2: Logging response headers
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
Above will log 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. (All possible values which can be given in pattern parameter can be found here [1])
“GET /example/servlets/servlet/RequestInfoExample?abc=xyz HTTP/1.1” ?abc=xyz 10.100.0.67
Example 4: Logging URL encoded parameters
You can’t use ‘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.
Here is the configuration.
Now, when we send following POST request with URL encoded values param1=value1 and param2=value2,
above configuration will log the following.
'value1' 'value2'
No comments:
Post a Comment