Versions Compared

Key

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

...

Logging is one of the most important aspects of a production-grade server. A properly configured logging system is vital in identifying errors, security threats and usage patterns. All WSO2 products are shipped with the log4j logging capabilities, which generates all the administrative activities and server side logs.  The log4j.properties file, which governs how logging is performed by the server, can be found in the <PRODUCT_HOME>/repository/conf directory.

 

Note that in addition to the logs from libraries that use Log4j, all logs from libraries (such as, Tomcat, Hazelcast and more) that use Java logging framework are also visible in log files. Therefore, when Java logging is enabled in Carbon, only the Log4j appenders will write to the log files. If the Java Logging Handlers have logs, these logs will be delegated to the log events of the corresponding Log4j appenders. A Pub/Sub registry pattern implementation has been used in the latter mentioned scenario to plug the handlers and appenders. The following default log4j appenders are used for this implementation:

 

  • org.wso2.carbon.logging.appenders.CarbonConsoleAppender
  • org.wso2.carbon.logging.appenders.CarbonDailyRollingFileAppender

Logging functionality is provided by the following feature in the WSO2 feature repository:

...

If the above feature is not bundled in your product by default, you can install it using the instructions given in the Feature Management section. Go to the documentation of your Carbon product for more details on how to use the logging feature. 

 

Java logging and Log4j Integration

Carbon 4.2.0 version onwards, in addition to the logs from libraries that use Log4j, all logs from the libraries (such as, Tomcat, Hazelcast and more) that use Java logging framework are also visible in log files.  Prior to this integration between Java logging and Log4j, when Java logging is enabled in Carbon, both Log4j and Java logging would try to write to the same .log files at the same time using two I/O streams. The latter will lead to log files getting corrupted. Furthermore, on Windows operating systems as file writing is a slower operation, the chance of log file corruption may be higher.

Therefore, as a result of this integration in Carbon 4.2.0, only the Log4j appenders will write to the log files. If the Java Logging Handlers have logs, these logs will be delegated to the log events of the corresponding Log4j appenders. A Pub/Sub registry pattern implementation has been used in the latter mentioned scenario to plug the handlers and appenders. 

Default Log4j  in the log4j.properties file appenders, such as ConsoleAppender and DailyRollingAppender have been extended to carryout this implementation as shown below.

...

Configuring products for logging

 

The log4j.properties file, which governs how logging is performed by the server, can be found in the <PRODUCT_HOME>/repository/conf directory. Given below are ways to configure log4j files: 

 

  • Manually editing the log4j.properties file.
  • In WSO2 products based on Carbon, you can configure logging through the management console. These changes will be applied at run time.

    Info

    In WSO2 products, using the management console is recommended, because all changes made to log4j through the management console persist in the WSO2 Registry. Therefore, those changes will be available after the server restarts. Changes that you make to the logging configuration via the management console will get priority over what is defined in the actual log4j.properties file. However, if you modify the log4j.properties file and restart the server, the earlier log4j configuration that persisted in the registry will be overwritten. There is also an option in the management console to restore the original log4j configuration from the log4j.properties file. 

 

Viewing logs 

 

In each product, the users can configure and adjust the logging levels for each type of activity/ transactions. There are several ways that the system and application logs of a running Carbon instance can be viewed.  

 

  • Through the Management Console. See Monitoring Logs for details.
  • Through the log files that are stored in the <PRODUCT_HOME>/repository/logs folder. This folder contains current logs in a log file with a date stamp. Older logs are archived in the wso2carbon.log file.
  • Through the command prompt/shell terminal that opens when running the "wso2server.bat"/"wso2server.sh" files to start the Carbon server.


Remedies for log growth

Log growth can be managed by the following configurations in the <PRODUCT_HOME>/repository/conf/log4j.properties file.

...