How to work with debug logs and troubleshoot WSO2 products

WSO2 Carbon redefines middleware by providing an integrated and componentized middleware platform that adapts to the specific needs of any enterprise IT project - on premise or in the cloud.
While using WSO2 products which is based on OSGi-based platform includes more than 175 components – OSGi bundles or Carbon features, Surely you will want to dig into code level for resolve issues, add new functionality or to modify current functionality. Therefore you might want to debug these codes. To do that we use remote debugging. Other-than remote debugging we sometimes want to get debug logs, First lets learn how to enable debug logs for specific package.


Step 1 : Locate log4j.properties file which can be found at <Carbon_Home>/repository/conf directory.

Step 2 : To enable debug logs for XYZ component you need to add the below line at the end of log4j.properties file.

log4j.logger.org.wso2.carbon.XYZ=DEBUG
Step 3 : Restart the server.

Step 4 : After you ran the scenario, collect the wso2carbon.log from <Carbon_Home>/repository/logs.

Step 5 : After your done with the process make sure to remove the line you include in step 2, since it may cause unwanted memory consumption.


After you analyse the debug logs you might want to add more debug points to the default code, Now lets learn how to achieve that task.

Step 1 : Correctly identify the location you need to get debug logs.

Step 2 : Write a debug statement(string) to get all the necessary data.
Note : Above step should be done very carefully.

Step 3 : Now insert the if (log.isDebugEnabled()) condition on the location you select in the step 1.
Please find the below code example for step 1 and 2.

Example : 

if (log.isDebugEnabled()) {

String debugLog = "getSubscribedAPIs > adding key.getAccessToken():" + key.getAccessToken() + ", key.getConsumerKey():" + key.getConsumerKey() + ", key.getConsumerSecret():" + key.getConsumerSecret() + " of application.getId():" + application.getId();

log.debug(issueLog);
}

After your done with the code you need to build it and follow the normal patch applying procedure[1].

[1] - http://stackoverflow.com/questions/11306929/how-to-apply-patch-files-in-wso2-carbon

Comments