Friday, October 21, 2016

How to Limit the WSO2 Service Log File Size

Limit the file size of wso2carbon.log

By default wso2carbon.log file is rotated on daily basis. But if we want to rotate the log files based on file size we can do as follows.

  • Change the log4j.appender.CARBON_LOGFILE appender in the /repository/conf/ file as follows. 


  • Add following two properties under the RollingFileAppender. You can change the MaxFileSize and MaxBackupIndex as Required.


MaxFileSize = Maximum allowed file size (in bytes) before rolling over. Suffixes "KB", "MB" and "GB" are allowed.
MaxBackupIndex  = Maximum number of backup files to keep
  • Now the configuration looks like below

# CARBON_LOGFILE is set to be a DailyRollingFileAppender using a PatternLayout.
# Log file will be overridden by the configuration setting in the DB
# This path should be relative to WSO2 Carbon Home
# ConversionPattern will be overridden by the configuration setting in the DB
log4j.appender.CARBON_LOGFILE.layout.ConversionPattern=TID: [%T] [%S] [%d] %P%5p {%c} - %x %m {%c}%n
log4j.appender.CARBON_LOGFILE.layout.TenantPattern=%U%@%D [%T] [%S]

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.For example if MaxBackupIndex is two you will see 3 files maximum. The wso2carbon.log.2 log file contains the oldest logs and wso2carbon.log contains the latest logs.


Disable Http Access Logs

HTTP Requests/Responses are logged in the access log(s) and are helpful to monitor your application's usage activities, such as the persons who access it, how many hits it receives, what the errors are etc. This information is useful for troubleshooting. As the runtime of WSO2 products are based on Apache Tomcat, you can use the AccessLogValve variable in Tomcat to configure HTTP access logs in WSO2 products.
The /repository/conf/tomcat/catalina-server.xml contains the valve related to the access logs as below. If you want to disable access logs comment out the below configuration.

<Valve className="org.apache.catalina.valves.AccessLogValve" directory="${carbon.home}/repository/logs"
 prefix="http_access_" suffix=".log"

Rotate Http Access Logs

We can achieve this by using "fileDateFormat". It allows a customized timestamp in the access log file name. The file is rotated whenever the formatted timestamp changes. The default value is yyyy-MM-dd. We can change it to rotate every hour by adding fileDateFormat to catalina-server.xml as follows. Tomcat itself does not do any housekeeping on the old files, so it is possible to have a cron job set up on the system to archive older files into a backup directory and/or delete them.

<Valve className="org.apache.catalina.valves.AccessLogValve" directory="${carbon.home}/repository/logs"
prefix="http_access_" suffix=".log"
pattern="combined" fileDateFormat="yyyy-MM-dd.HH"/>

No comments:

Post a Comment