Manta Logback Rollover

October 28, 2015 ยท View on GitHub

This is a implementation of a Logback RollingPolicy that copies logs triggered for archival to the open-source Manta storage system.

Configuration

Configuration can be done in one of three ways:

  • The Logback configuration file.
  • As Java system properties.
  • As environment variables.
LogbackJava System PropertyEnvironment Variable
mantaUrlmanta.urlMANTA_URL
mantaUsermanta.userMANTA_USER
mantaKeyPathmanta.key_pathMANTA_KEY_PATH
mantaKeyFingerprintmanta.key_fingerprintMANTA_KEY_ID
mantaLogDirectorymanta.log_directoryMANTA_LOG_DIR
mantaRetryAttemptsmanta.retry_attemptsMANTA_RETRY_ATTEMPTS
mantaDurabilityLevelmanta.durability_levelMANTA_DURABILITY_LEVEL

We will look first at any values in the Logback configuration, then we will look in the Java system properties and finally we will look for an environment variable specifying the setting.

As of right now, we don't have defaults for any of the settings. That said, here are some sensible defaults and sample values:

mantaUrl             = https://us-east.manta.joyent.com
mantaUser            = username
mantaKeyPath         = /home/user/.ssh/manta_id_rsa
mantaKeyFingerprint  = 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00
mantaLogDirectory    = /mantauser/stor/logs/
mantaRetryAttempts   = 3
mantaDurabilityLevel = 3

Here's what a sample roll-over configuration may look like:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} ${HOSTNAME} [%thread] %-5level [%X{tracker}] %logger - %msg%n</pattern>
        </encoder>
    </appender>

    <appender name="RolloverFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <encoder>
            <charset>utf-8</charset>
            <pattern>%msg%n</pattern>
        </encoder>
        <append>true</append>
        <file>logs/rollover.log</file>

        <rollingPolicy class="ch.qos.logback.core.rolling.MantaTimeBasedRollingPolicy">
            <!-- Manta Rollover variables -->
            <mantaRetryAttempts>3</mantaRetryAttempts>
            <mantaDurabilityLevel>3</mantaDurabilityLevel>
            <!-- Assume that the other variables came in via system properies -->

            <fileNamePattern>logs/archive/rollover-%d{yyyy-MM-dd}-%i.log.gz</fileNamePattern>
            <timeBasedFileNamingAndTriggeringPolicy
                    class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>1GB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
        </rollingPolicy>
    </appender>

    <logger name="rollover.test" level="trace" additivity="false">
        <appender-ref ref="RolloverFile" />
    </logger>

    <root level="debug">
        <appender-ref ref="Console" />
    </root>
</configuration>