[logback-dev] [JIRA] (LOGBACK-1442) Adding "originalFileName" token to FileNamePattern or TimeBasedRollingPolicy

QOS.CH (JIRA) noreply-jira at qos.ch
Wed Nov 28 11:01:00 CET 2018


Anton Pryamostanov created LOGBACK-1442:
-------------------------------------------

             Summary: Adding "originalFileName" token to FileNamePattern or TimeBasedRollingPolicy
                 Key: LOGBACK-1442
                 URL: https://jira.qos.ch/browse/LOGBACK-1442
             Project: logback
          Issue Type: Improvement
          Components: logback-classic
         Environment: Let's consider the below example:
{code:xml}
    <appender name="OutputInfo" class="ch.qos.logback.classic.sift.SiftingAppender">
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>ERROR</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
        <discriminator>
            <key>automaticThreadName</key>
            <defaultValue>Unnamed Thread</defaultValue>
        </discriminator>
        <discriminator>
            <key>inputQueueName</key>
            <defaultValue>APP</defaultValue>
        </discriminator>
        <discriminator>
            <key>outputQueueName</key>
            <defaultValue>APP</defaultValue>
        </discriminator>
        <sift>
            <appender name="${automaticThreadName}" class="ch.qos.logback.core.rolling.RollingFileAppender">
                <file>./LOGS/${inputQueueName}/${outputQueueName}/ERROR/${automaticThreadName}_ERROR_TODAY.log</file>
                <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
                    <Pattern>%d{yyyy-MM-dd HH:mm:ss} %mdc [%thread] %level %logger{35} - %msg%n</Pattern>
                </encoder>
                <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                    <FileNamePattern>./LOGS/${inputQueueName}/${outputQueueName}/ERROR/ARCHIVE/%d{yyyyMMdd, aux}/${automaticThreadName}_%d{yyyyMMdd}_ERROR.zip</FileNamePattern>
                </rollingPolicy>
            </appender>
        </sift>
    </appender>
 {code}

It is not a valid example because FileNamePattern of TimeBasedRollingPolicy does not support MDC tokens like the SiftingAppender supports.

This is causing a significant limitation for SiftingAppender log archiving - a diversity of file names of SiftingAppender can be archived only into a narrow list of archives due to TimeBasedRollingPolicy not supporting MDC tokens.

This can be easily fixed just by adding 3 tokens into TimeBasedRollingPolicy FileNamePattern, which will represent:
- %q - qualified file name of original physical file, e.g. ./logs/thread1/20181115/thread1_errors.log
- %f - only file name of original physical file, e.g. "thread1_errors.log"
- %p - only path of original physical file, e.g. "./logs/thread1/20181115/"

Therefore the above config will look like:
{code}
    <appender name="OutputInfo" class="ch.qos.logback.classic.sift.SiftingAppender">
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>ERROR</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
        <discriminator>
            <key>automaticThreadName</key>
            <defaultValue>Unnamed Thread</defaultValue>
        </discriminator>
        <discriminator>
            <key>inputQueueName</key>
            <defaultValue>APP</defaultValue>
        </discriminator>
        <discriminator>
            <key>outputQueueName</key>
            <defaultValue>APP</defaultValue>
        </discriminator>
        <sift>
            <appender name="${automaticThreadName}" class="ch.qos.logback.core.rolling.RollingFileAppender">
                <file>./LOGS/${inputQueueName}/${outputQueueName}/ERROR/${automaticThreadName}_ERROR_TODAY.log</file>
                <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
                    <Pattern>%d{yyyy-MM-dd HH:mm:ss} %mdc [%thread] %level %logger{35} - %msg%n</Pattern>
                </encoder>
                <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                    <FileNamePattern>%q.zip</FileNamePattern>
                </rollingPolicy>
            </appender>
        </sift>
    </appender>
{code}
            Reporter: Anton Pryamostanov
            Assignee: Logback dev list






--
This message was sent by Atlassian JIRA
(v7.3.1#73012)


More information about the logback-dev mailing list