User Community Service Desk Downloads
If you can't find the product or version you're looking for, visit support.ataccama.com/downloads

Advanced Rolling File Appender Configuration

It is possible to save logging information to a rotating file with configurable rotation policies. In the following example, the output from ONE Runtime Server using the LoggingComponent is stored to a text file that is rotated according to the time configured or after the size of the file exceeds the defined size limit.

Rolling policies

A rolling policy describes the rollover procedure, which means it dictates the behavior of the RollingFileAppender when the rollover occurs. There are two most common implementations: TimeBasedRollingPolicy and SizeAndTimeBasedRollingPolicy.

Both of these classes provide not just the description of what exactly has to happen when the rollover occurs, but they also specify when the rollover is going to be initiated.

TimeBasedRollingPolicy

This policy defines a rollover based on time, for example by day or by month. It assumes the responsibility for rollover as well as for initiating the said rollover.

The configuration takes one mandatory fileNamePattern property and several optional properties.

  • fileNamePattern: Defines the name of the rolled-over (archived) log files. For details, see fileNamePattern property.

  • maxHistory: Controls the maximum number of archive files to keep, asynchronously deleting older files.

  • totalSizeCap: Controls the total size of all archive files.

  • cleanHistoryOnStart: If set to true, archive removal is executed on appender startup.

SizeAndTimeBasedRollingPolicy

If you wish to limit the size of individual files as well as the time, use this implementation. This policy initiates a rollover either when the rollover period is reached (similarly to the TimeBasedRollingPolicy) or when the file size of the active log file reaches the limit defined by maxFileSize property.

  • maxFileSize: Can be specified in bytes, kilobytes, megabytes, or gigabytes by concatenating the unit (kB, MB, or GB respectively) to a numeric value. For example, 5,000,000, 5,000kB, 5MB, and 2GB are all valid values.

  • All properties from the TimeBasedRollingPolicy.

fileNamePattern property

The mandatory fileNamePattern property defines the name of the rolled-over (archived) log files. Its value should consist of the name of the file, plus a suitably placed %d conversion specifier. The %d conversion specifier can contain a date-and-time pattern as specified by the java.text.SimpleDateFormat class.

If the date-and-time pattern is omitted, then the default pattern yyyy-MM-dd is assumed. The rollover period is inferred from the value of the fileNamePattern attribute.

Note that the file property in RollingFileAppender can be either set or omitted. By setting the file property you can decouple the location of the active log file and the location of the archived log files.

The current logs are always targeted at the file specified by the file property. It follows that the name of the currently active log file does not change over time. However, if you choose to omit the file property, then the active file is computed anew for each period based on the value of fileNamePattern.

The date-and-time pattern, as found within the %d{}, follows the java.text.SimpleDateFormat conventions. The forward slash (/) or backward slash (\) characters anywhere within the fileNamePattern property or within the date-and-time pattern are interpreted as directory separators. It is possible to specify multiple %d specifiers but only one of them can be primary, that is, used to infer the rollover period.

All other tokens must be marked as auxiliary by passing the 'aux' parameter (see the following example). Multiple %d specifiers allow you to organize archive files in a folder structure different than that of the rollover period.

For example, the file name pattern shown here organizes log folders by year and month but rollover log files every day at midnight.

/var/log/%d{yyyy/MM, aux}/myapplication.%d{yyyy-MM-dd}.log

Configuration of the LoggingComponent

  1. Open the logging configuration file used by the server: the logging configuration is located in <ATACCAMA_HOME>/server/etc/logback-extension.xml.

  2. Set up a new appender that will be used to write the incoming messages. In this example, the RollingFileAppender class is used, which provides the features for file rotation.

  3. Modify the file and fileNamePattern attributes and use the same appender name in the appender-ref element in the logger.

  4. Save the configuration and restart the server.

logback-extension.xml
<?xml version="1.0" encoding="UTF-8"?>
<included>
    <!-- <property name="root.level" value="INFO" /> -->
    <!-- <property name="stdout.level" value="INFO" /> -->
    <!-- <property name="ataccama.level" value="INFO" /> -->
    <!-- <property name="ataccama.stdout.level" value="INFO" /> -->
    <!-- <property name="ataccama.additivity" value="false" /> -->

    <appender name="rolling-log" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>../storage/server.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>../storage/server-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
            <maxFileSize>100MB</maxFileSize>
            <maxHistory>60</maxHistory>
            <totalSizeCap>2GB</totalSizeCap>
        </rollingPolicy>
        <encoder>
            <pattern>%d{yyy.MM.dd HH:mm:ss} %-7([%level]) %msg%n</pattern>
        </encoder>
    </appender>

    <logger name="ataccama" level="info" additivity="false">
        <appender-ref ref="rolling-log" />
    </logger>

</included>

Was this page useful?