Issue
- We would like to move a trace from the main log file to a separate log file.
Environment
- DXP 7.3+
- Quarterly Release
Resolution
-
We can use a
portal-log4j-ext.xmlfile to to add a new appender where we specify the name of the additional log file:1. Edit
portal-log4j-ext.xml.2. Add a new appender for your log file (myLog....log), i.e.:
<appender class="org.apache.log4j.rolling.RollingFileAppender" name="MY_LOG_TEXT_FILE">
<rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
<param name="FileNamePattern" value="@liferay.home@/logs/myLog@spi.id@.%d{yyyy-MM-dd}.log" />
</rollingPolicy>
<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>3. Add your new appender to the
<root>tag:<root>
<priority value="INFO" />
<appender-ref ref="CONSOLE" />
<appender-ref ref="TEXT_FILE" />
<appender-ref ref="XML_FILE" />
<appender-ref ref="MY_LOG_TEXT_FILE" />
</root>4. One way to filter the traces could be by text, this can be achieved by adding filters to each appender to display or not the traces containing that text:
Displays the trace in the log:<filter class="org.apache.log4j.varia.StringMatchFilter">
<param name="StringToMatch" value="Tex to filter" />
<param name="AcceptOnMatch" value="true" />
</filter>Not displays the trace in the log:
<filter class="org.apache.log4j.varia.StringMatchFilter">
<param name="StringToMatch" value="Tex to filter" />
<param name="AcceptOnMatch" value="false" />
</filter>
Additional Information
- Check https://help.liferay.com/hc/en-us/articles/360050830051-Adjusting-Log-Levels-to-persist-after-portal-restart, steps 1 to 4, to see how to use a
portal-log4j-ext.xmlfile. -
Attached a
portal-log4j-ext.xmlas an example for 7.3.x.