Configuring Log4j Logging for the Audit Portlet in Liferay Portal EE

This article demonstrates how to create a separate audit.YYYY-MM-DD.log file within ${liferay.home}/logfor audit INFO messages. It should roll over every day with this configuration. 

Environment

  • Liferay Portal EE 6.1 & 6.2

Resolution

Please note: For the following procedures we will use a Liferay Tomcat bundle. Be sure to make the proper adjustments specific to the application server in use.

Procedure in Liferay Portal 6.1 and 6.2 

  1. Make sure the Liferay Audit portlet is successfully deployed from Liferay Marketplace.
  2. Within ${tomcat.home}/webapps/audit-portlet/WEB-INF/classes/META-INF/audit-spring.xml verify that com.liferay.portal.audit.LogAuditRouterProcessor bean is already enabled.
    <property name="globalAuditMessageProcessors">
        <list value-type="com.liferay.portal.kernel.audit.AuditMessageProcessor">
            <ref bean="com.liferay.portal.audit.DatabaseAuditRouterProcessor" />
            <ref bean="com.liferay.portal.audit.LogAuditRouterProcessor" />
        </list>
    </property>
    
  3. Extract both log4j.dtd from ${tomcat.home}/webapps/ROOT/WEB-INF/lib/portal-impl.jar into ${tomcat.home}/webapps/ROOT/WEB-INF/classes/META-INF
  4. Create portal-log4j-ext.xml and place it into ${tomcat.home}/webapps/ROOT/WEB-INF/classes/META-INF
  5. Add the following information into portal-log4j-ext.xml
    <?xml version="1.0"?>
    <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">     <!-- additional audit logging -->     <appender name="auditFile" class="org.apache.log4j.rolling.RollingFileAppender">
            <rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
                <param name="FileNamePattern" value="@liferay.home@/logs/audit.%d{yyyy-MM-dd}.log" />
            </rollingPolicy>
            <layout class="org.apache.log4j.EnhancedPatternLayout">
                <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%t][%c{1}:%L] %m%n" />
            </layout>
        </appender>     <category name="com.liferay.portal.audit.LogAuditRouterProcessor">
            <priority value="INFO" />
            <appender-ref ref="auditFile"/>
        </category> </log4j:configuration>
  6. Restart the server and verify that the audit log file is created within ${liferay.home}/logs

 

这篇文章有帮助吗?
0 人中有 0 人觉得有帮助