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)