Saturday, June 10, 2017

WSO2 Products - HTTP Access Logging (create a log file without including timestamp)

You can use access logs to investigate the entries for service and REST API invocations and for Management Console access. Access logs are helpful to monitor your application's usage activities, such as the persons who access it, how many hits it receives, what the errors and many more. 

These information is useful when troubleshooting happens.

In WSO2 products you can customize the http access log configuration by editing the catalina-server.xml which is located


<PRODUCT_HOME>/repository/conf/tomcat/catalina-server.xml

 As the runtime of WSO2 products are based on Apache Tomcat, you can use the Access_Log_Valve variable in Tomcat 7 as explained below to configure HTTP access logs in WSO2 products. In addition, you can customize the access logs based on the supported Access Log Valve attributes.


Create access.log  without appending Date in to the file name


By default Tomcat server will create a log file with including timestamp. 

When the server is running on next day, it will create a new log file. 

The objective of this default behavior is to avoid issues when the log file eventually becomes larger. But when you set the rotatable property to "false", it will disable this default behavior and use a single log file.

We can  change this behavior by configuring either the "rotatable" parameter or "renameOnRotate" parameter in access-log valve section of catalina-server.xml as below. Make sure to change the prefix property as "http_access".


  • Using "rotatable" property



<Valve className="org.apache.catalina.valves.AccessLogValve" directory="$
{carbon.home}/repository/logs"
prefix="http_access" suffix=".log"
pattern="combined" rotatable="false"/>


  • Using "renameOnRotate" property



<Valve className="org.apache.catalina.valves.AccessLogValve" directory="${carbon.home}
/repository/logs"
prefix="http_access" suffix=".log"
pattern="combined" renameOnRotate="true"/>


By setting the renameOnRotate property to "true", tomcat server will not include a timestamp to the log file. So Tomcat will use "http-access.log" file for logging.

 But it'll rename it to include the timestamp when the rotation happens (at the beginning of the next day) and create a new http-access.log file for logging.


During rotation the file is closed and a new file with the next timestamp in the name is created and used. When setting renameOnRotate to true, the timestamp is no longer part of the active log file name. Only during rotation the file is closed and then renamed to include the timestamp. 

This is similar to the behavior of most log frameworks when doing time based rotation."