Issue
- How to implement the log rotation for Liferay logs based on the size
Environment
- Liferay Portal 6.2
- Liferay DXP 7.0
Resolution
-
The logs can be rotated based on the size and it can be achieved through a very slight change in
portal-log4j.xml. This file can be found in\webapps\ROOT\WEB-INF\lib\portal-impl.jar\META-INF\. Also, to make changes in the default file, it is suggested to create a portal-log4j-ext.xml and insert the desired changes there, to avoid making a permanent change to the original file and place it in this location ${TOMCAT_HOME}/webapps/ROOT/WEB-INF/classes/META-INF.log4j.appender.DAILY=org.apache.log4j.DailyRollingFileAppender
log4j.appender.DAILY.File=/logs/liferay.log
log4j.appender.DAILY.DatePattern='.'yyyy-MM-dd
log4j.appender.DAILY.layout=org.apache.log4j.PatternLayout
log4j.appender.DAILY.layout.conversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} [%p] %c:%L - %m%n
log4j.appender.DAILY.MaxFileSize=100KB
log4j.appender.DAILY.MaxBackupIndex=5Note: The file is rolled over after a specified size has been reached. i.e. This log4j.properties file will create a log file named liferay.log in the folder /logs. If this file exceeds a size of 100KB, it will be renamed to liferay.log.1 and replaced by a new liferay.log file. A maximum of 5 such backup files will be created. To configure max file size in megabytes, use MB as in 20MB. Please reach out to the Liferay Global Services team for further help.