Legacy Knowledge Base
Published Sep. 10, 2025

How to write some logs to a different log file

Written By

Daniel Mijarra

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

Legacy Article

You are viewing an article from our legacy "FastTrack" publication program, made available for informational purposes. Articles in this program were published without a requirement for independent editing or verification and are provided"as is" without guarantee.

Before using any information from this article, independently verify its suitability for your situation and project.

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.xml file 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

Did this article resolve your issue ?

Legacy Knowledge Base