This Confluence has been LDAP enabled, if you are an ASF Committer, please use your LDAP Credentials to login. Any problems file an INFRA jira ticket please.

Child pages
  • Configure Log4j CompositeRolling Appender
Skip to end of metadata
Go to start of metadata

How to configure the CompositeRolling log4j Appender

There are several sections of our default log4j file that will need your attention if you wish to fully use this Appender.

1 Enable the Appender

The default log4j.xml file uses the FileAppender, swapp this for the ArchivingFileAppender as follows:

    <!-- Log all info events to file -->
    <root>
        <priority value="info"/>

        <appender-ref ref="ArchivingFileAppender"/>
    </root>

2 Configure the Appender

The Appender has a number of parameters that can be adjusted depending on what you are trying to achieve. For clarity lets take a quick look at the complete default appender:

  <appender name="ArchivingFileAppender" class="org.apache.log4j.QpidCompositeRollingAppender">
        <!-- Ensure that logs allways have the dateFormat set-->
        <param name="StaticLogFileName" value="false"/>
        <param name="File" value="${QPID_WORK}/log/${logprefix}qpid${logsuffix}.log"/>
        <param name="Append" value="false"/>
        <!-- Change the direction so newer files have bigger numbers -->
        <!-- So log.1 is written then log.2 etc This prevents a lot of file renames at log rollover -->
        <param name="CountDirection" value="1"/>
        <!-- Use default 10MB -->
        <!--param name="MaxFileSize" value="100000"/-->
        <param name="DatePattern" value="'.'yyyy-MM-dd-HH-mm"/>
        <!-- Unlimited number of backups -->
        <param name="MaxSizeRollBackups" value="-1"/>
        <!-- Compress(gzip) the backup files-->
        <param name="CompressBackupFiles" value="true"/>
        <!-- Compress the backup files using a second thread -->
        <param name="CompressAsync" value="true"/>
        <!-- Start at zero numbered files-->
        <param name="ZeroBased" value="true"/>
        <!-- Backup Location -->
        <param name="backupFilesToPath" value="${QPID_WORK}/backup/log"/>

        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/>
        </layout>
    </appender>

The appender configuration has three groups of parameter configuration.

The first group is for configuration of the file name. The default is to write a log file to QPID_WORK/log/qpid.log (Remembering you can use the logprefix and logsuffix values to modify the file name, see Property Config).

        <!-- Ensure that logs always have the dateFormat set-->
        <param name="StaticLogFileName" value="false"/>
        <param name="File" value="${QPID_WORK}/log/${logprefix}qpid${logsuffix}.log"/>
        <param name="Append" value="false"/>

The second section allows the specification of a Maximum File Size and a DatePattern that will be used to move on to the next file.

When MaxFileSize is reached a new log file will be created
The DataPattern is used to decide when to create a new log file, so here a new file will be created for every minute and every 10Meg of data. So if 15MB of data is made every minute then there will be two log files created each minute. One at the start of the minute and a second when the file hit 10MB. When the next minute arrives a new file will be made even though it only has 5MB of content. For a production system it would be expected to be changed to something like 'yyyy-MM-dd' which would make a new log file each day and keep the files to a max of 10MB.

The final MaxSizeRollBackups allows you to limit the amount of disk you are using by only keeping the last n backups.

        <!-- Change the direction so newer files have bigger numbers -->
        <!-- So log.1 is written then log.2 etc This prevents a lot of file renames at log rollover -->
        <param name="CountDirection" value="1"/>
        <!-- Use default 10MB -->
        <!--param name="MaxFileSize" value="100000"/-->
        <param name="DatePattern" value="'.'yyyy-MM-dd-HH-mm"/>
        <!-- Unlimited number of backups -->
        <param name="MaxSizeRollBackups" value="-1"/>

The final section allows the old log files to be compressed and copied to a new location.

        <!-- Compress(gzip) the backup files-->
        <param name="CompressBackupFiles" value="true"/>
        <!-- Compress the backup files using a second thread -->
        <param name="CompressAsync" value="true"/>
        <!-- Start at zero numbered files-->
        <param name="ZeroBased" value="true"/>
        <!-- Backup Location -->
        <param name="backupFilesToPath" value="${QPID_WORK}/backup/log"/>
  • No labels