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 for identifying errors, security threats and usage patterns. All WSO2 products are shipped with the log4j logging capabilities, which generates 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.

 

Java logging and Log4j integration: 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 the same log files. That is, 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 in the log4j.properties file are used for this implementation: 

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

...

  • 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 you run the "wso2server.bat"/"wso2server.sh" files to start the Carbon server.   
  • Through the advanced monitoring capabilities in WSO2 BAM. 
  • Through the management console of your product.

Limiting the size of the wso2carbon.log file

You can limit the size of the <PRODUCT_HOME>/repository/logs/wso2carbon.log file by following the steps given below. This is useful if you want to archive the logs and get backups periodically.

  1. Add org.apache.log4j.RollingFileAppender as the value of the log4j.appender.CARBON_LOGFILE property in the <PRODUCT_HOME>/repository/conf/log4j.properties file as follows.
    log4j.appender.CARBON_LOGFILE=org.apache.log4j.RollingFileAppender
  2. Add the following two properties under RollingFileAppender.

    log4j.appender.CARBON_LOGFILE.MaxFileSize=10MB 
    log4j.appender.CARBON_LOGFILE.MaxBackupIndex=20

    Info

    If the size of the log file is exceeding the value defined in the MaxFileSize property, then the content is copied to a backup file and the logs are continued to be added to a new empty log file. The MaxBackupIndex property makes the Log4j keep a given maximum number of backup files for the logs.