0
votes

In Liferay 6.2 we had a seperate logfile for each portlet inside the tomcat/logs Folder. In Liferay 7.1 we do not have this anymore, all the logs of all the portlets are written to webapps.log.

Is there any approach to also have one logfile per portlet in Liferay DXP? We are using Spring MVC Portlets, and not OSGI Modules.

1

1 Answers

1
votes

You can try the following approach which works at least for OSGI MVC Portlets:

Create the file [Your Server]/ROOT/WEB-INF/classes/META-INF/portal-log4j-ext.xml

and add

    <appender name="MY-PORTLET_FILE" class="org.apache.log4j.rolling.RollingFileAppender">
        <rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
            <param name="FileNamePattern" value="@liferay.home@/logs/[Your Filename].%d{yyyy-MM-dd}.log" />
        </rollingPolicy>

        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}:%L] %m%n" />
        </layout>
    </appender>

    <category name="[Your Portlet Classname]" >
        <priority value="DEBUG" />
        <appender-ref ref="MY-PORTLET_FILE" />
    </category>

Then in the portlet class create the logger like this:

    Log logger = LogFactoryUtil.getLog(this.getClass().getName());

This is also desribed here https://liferay.dev/blogs/-/blogs/how-to-disable-xml-log-files-in-7-x and works with Liferay 7.3.2 GA