Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Enhanced log4j monitoring for DXP 7.1 - tomcat/webapps/ROOT/WEB-INF/classes/META-INF/portal-log4j-ext.xml
<?xml version="1.0"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender class="org.apache.log4j.rolling.RollingFileAppender" name="TEXT_FILE">
<!-- Inspired by: http://www.baeldung.com/java-logging-rolling-file-appenders -->
<!--
=== What happens when current log file needs to be rotated? ===
-->
<!-- (A)
* archived files named with index (*.0.log.gz - *.12.log.gz),
* archived files gzipped,
* oldest archived files removed (overwritten by newer ones) -->
<rollingPolicy class="org.apache.log4j.rolling.FixedWindowRollingPolicy">
<param name="ActiveFileName" value="@liferay.home@/logs/liferay@spi.id@.current.log" />
<param name="FileNamePattern" value="@liferay.home@/logs/liferay@spi.id@.%i.log.gz" />
<param name="MinIndex" value="0" />
<param name="MaxIndex" value="12" /> <!-- 13 is the maximum size of the window -->
</rollingPolicy>
<!-- (B)
* archived files named with daily timestamp + int (millis - in case there
are more files to be archived on the same day)
* archived files gzipped,
* no old archived files removed (kept gzipped indefinitely) -->
<!--<rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">-->
<!--<param name="ActiveFileName" value="@liferay.home@/logs/liferay@spi.id@.current.log" />-->
<!--&lt;!&ndash; gzip log files when rotation happens - when new log file is started &ndash;&gt;-->
<!--<param name="FileNamePattern" value="@liferay.home@/logs/liferay@spi.id@.%d{yyyy-MM-dd}.%i.log.gz" />-->
<!--</rollingPolicy>-->
<!-- (C) - original in Liferay
* archived files named with daily timestamp,
* archived files NOT gzipped,
* no old archived files removed (kept non-gzipped indefinitely) -->
<!--<rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">-->
<!--<param name="FileNamePattern" value="@liferay.home@/logs/liferay@spi.id@.%d{yyyy-MM-dd}.log" />-->
<!--</rollingPolicy>-->
<!--
=== When is current log file rotated? ===
-->
<!-- (a)
* when its size limit is reached -->
<triggeringPolicy class="org.apache.log4j.rolling.SizeBasedTriggeringPolicy">
<!-- make sure the active log file won't grow out of bounds -->
<!-- must be in bytes:
104857600 ~ 100 MB (100 * 1024 * 1024 B) -->
<param name="MaxFileSize" value="104857600" />
</triggeringPolicy>
<!-- (b) - original in Liferay
* daily on midnight (based on TimeBasedRollingPolicy);
* this is used when no explicit 'triggeringPolicy' is defined,
* comment out (a) above if you want to use this strategy -->
<!--
=== What is the format of every logged event? ===
-->
<layout class="org.apache.log4j.EnhancedPatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p [%t][%c{1}:%L] %m%n" />
</layout>
</appender>
<root>
<priority value="INFO" />
<appender-ref ref="CONSOLE" />
<appender-ref ref="TEXT_FILE" />
<!-- no XML_FILE appender, never used -->
</root>
</log4j:configuration>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment