How to enable log-rotation for the error.log

Note: This article does not apply to CRX2.3.  In CRX 2.3 the logging configuration is done via the Apache Sling Logging Logger as defined here.  Steps for log rotation can be found there as well.

Question / Problem

The error.log of CRX is currently not rotated, thus it can grow unbounded. In order to limit both the file-size and number of rotations, it is possible to configure this using standard Log4j capabilities.

Answer / Resolution

To reconfigure the error.log of CRX, simply edit the log4j.xml configuration file of the CRX webapp. This is located beneath the /WEB-INF folder of the deployed CRX webapp.

Please edit the section for the error appender and do the following:

  • change the class of the appender to org.apache.log4j.RollingFileAppender
  • add additional parameter maxBackupIndex to define the maximum number of rotated log-files to keep (default: 1 if missing)
  • optional: add parameter maxFileSize to limit the maximum file size of a rotated log-file (default: 10MB if missing)

Excerpt from log4j.xml

<appender name="error" class="org.apache.log4j.RollingFileAppender">
    <param name="maxBackupIndex" value="5" />
    <param name="File" value="crx-quickstart/logs/crx/error.log"/>
    <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" value="%d{dd.MM.yyyy HH:mm:ss} *%-5p* %c{1}: %m (%F, line %L)%n"/>
    </layout>
</appender>

This change will take effect after a repository restart. For more information, please refer to [1].

Applies

CRX1.3.x, CRX1.4.x, CRX 2.2.x

[1] http://wiki.apache.org/logging-log4j/Log4jXmlFormat

 Adobe

Få hjälp snabbare och enklare

Ny användare?