Issue
- Configuring log rotation for logs based on the size.
Environment
- Liferay DXP 7.4
Resolution
- The logs can be rotated based on size by making a small adjustment in the
portal-log4j.xmlfile. - Extract
portal-impl.jarfrom/tomcat-9.0.73/webapps/ROOT/WEB-INF/shielded-container-lib/and copy theportal-log4j.xmlfile. Then, pasteportal-log4j.xmlinto${TOMCAT_HOME}/webapps/ROOT/WEB-INF/classes/META-INFand rename it toportal-log4j-ext.xml. -
Modify both
<Appender>blocks for.logand.xmlinportal-log4j-ext.xmlto enable log rotation based on size. Following is the sample configuration for reference:
<Appender name="TEXT_FILE" type="RollingFile"
fileName="@liferay.home@/logs/liferay.log"
filePattern="@liferay.home@/logs/liferay.%d{yyyy-MM-dd}-%i.log.gz"
ignoreExceptions="false">
<Layout type="PatternLayout" pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p [%t][%c{1}:%L] %m%n" />
<Policies>
<SizeBasedTriggeringPolicy size="10KB"/>
</Policies>
<DefaultRolloverStrategy max="30"/>
</Appender>
<Appender name="XML_FILE" type="RollingFile"
fileName="@liferay.home@/logs/liferay.xml"
filePattern="@liferay.home@/logs/liferay.%d{yyyy-MM-dd}-%i.xml.gz"
ignoreExceptions="false">
<Log4j1XmlLayout locationInfo="true" />
<Policies>
<SizeBasedTriggeringPolicy size="10KB"/>
</Policies>
<DefaultRolloverStrategy max="30"/>
</Appender> -
Note: The file is rolled over after reaching a specified size of 10KB, creating a maximum of 30 log files. Initially, the log file is named
liferay.log. Once it reaches 10KB, it is renamed toliferay.2024-08-22-1.log.gz.