logbacksifting-appender

LogBack: SiftingAppender not working anymore after upgrading to 1.4


We use the ch.qos.logback.classic.sift.SiftingAppender to create a separate log file for each of our imports. For that end we create a property importLogFile and put it into the MDC, the config looks as follows:

<appender name="MyImport" class="ch.qos.logback.classic.sift.SiftingAppender">
    <discriminator>
        <key>importLogFile</key>
        <defaultValue>undefined</defaultValue>
    </discriminator>
    
    <filter class="ch.qos.logback.core.filter.EvaluatorFilter">
        <evaluator class="ch.qos.logback.classic.boolex.JaninoEventEvaluator">
            <expression>
                return mdc == null || mdc.get("importLogFile") == null;
            </expression>
        </evaluator>
        <OnMismatch>NEUTRAL</OnMismatch>
        <OnMatch>DENY</OnMatch>
    </filter> 
    
    <sift>
        <appender name="FILE-${importLogFile}" class="ch.qos.logback.core.FileAppender">
            <file>${importLogFile}</file>
            <append>false</append>
            <layout class="ch.qos.logback.classic.PatternLayout">
                <pattern>%d %level %logger{35} - %msg%n</pattern>
            </layout>
        </appender>
    </sift>
</appender>

We followed the docs in that matter, see here.

This worked flawlessly while we were using logback 1.2.x. With the update to version 1.3 though, the initialization process seems to have changed. We're trying to use the latest version (1.4.4 (ch.qos.logback:logback-classic:1.4.4), and now instead of separate log files we get following error message during startup of our web app:

Appender named [FILE-importLogFile_IS_UNDEFINED] not referenced. Skipping further processing.
ERROR in ch.qos.logback.classic.sift.SiftingAppender[MyImport] - AppenderFactory has not been set. Aborting

I did not find a solution for this in the logback docs. There were changes concerning the usage of nested appenders (some other log messages indicate as much) but as far as I understand the SiftingAppender does not really fall under that category - and the docs mentioned above haven't been changed, so I guess that approach should still be valid.

Hints and tips really appreciated :-)


Solution

  • Turned out that the problem has been a bug in Logback, see https://jira.qos.ch/browse/LOGBACK-1713 for the details.

    With version 1.4.6 everything works as expected again - which is really great :-)