How to disable XML Log Files in Liferay 7.x


Liferay 7.0 started to produce a pair of log files per day:

ls -l /opt/liferay/home7/logs/
total 3104
-rw-r--r--  1 michael  admin  285201 May 26 13:24 liferay.2016-05-26.log
-rw-r--r--  1 michael  admin  898027 May 26 13:24 liferay.2016-05-26.xml
-rw-r--r--  1 michael  admin  400811 Aug 19 13:08 liferay.2016-08-19.log
-rw-r--r--  1 michael  admin       0 Aug 19 12:26 liferay.2016-08-19.xml

To disable Liferay logging to XML files, create portal-log4j-ext.xml in the following path:

tomcat-8.0.32/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">
        <rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
            <param name="FileNamePattern" value="@liferay.home@/logs/liferay@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>

    <appender name="XML_FILE" class="org.apache.log4j.ConsoleAppender"/>
 
    <root>
        <priority value="INFO" />
        <!--appender-ref ref="CONSOLE" /-->
        <appender-ref ref="TEXT_FILE" />
        <!--appender-ref ref="XML_FILE" /-->
    </root>
</log4j:configuration>

This file overrides two elements of META-INF/portal-log4j.xml in ROOT/WEB-INF/lib/portal-impl.jar, which stops Liferay from copying log entries to catalina.out and the daily XML log file.

You can also create the extension XML file as a copy of the original in the JAR as the following:

cd tomcat-8.0.32/webapps/ROOT/WEB-INF
unzip -p lib/portal-impl.jar META-INF/portal-log4j.xml > classes/META-INF/portal-log4j-ext.xml

This has been tested to work in both 7.0 and 7.1.

3
Blogs

Hi, I just tested this and although it works it still creates the xml file (obvious, the appender is there but not configured). Is there a way to remove the appender  ?

If you don't want an empty xml file to be created, the file name should be " portal-log4j.xml" instead of " portal-log4j-ext.xml"