Search code examples
javalogback

Append set to false, but still got warn for missing append mode, and defaulting it to true


I have a strange problem. Got appender set to false in my logback.xml, but still got warn and setting it back to true.

|-WARN in ch.qos.logback.core.rolling.RollingFileAppender[file] - Append mode is mandatory for RollingFileAppender. Defaulting to append=true.

Here is my appender:

<appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>logs/test.logs</file>
        <append>false</append>
        <encoder>
            <pattern>%d{dd/MM/yyyy HH:mm:ss} %c %m%n</pattern>
        </encoder>
        <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
            <maxIndex>6</maxIndex>
            <FileNamePattern>logs/test.logs.%i</FileNamePattern>
        </rollingPolicy>
        <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
            <maxFileSize>5MB</maxFileSize>
        </triggeringPolicy>
</appender>

UPDATE: I noticed there's an Error message also, it seems it can't recognise append:

ERROR in ch.qos.logback.core.joran.spi.Interpreter@5:16 - no applicable action for [append], current ElementPath  is [[configuration][appender][append]]

Solution

  • The warning message is a little bit confusing. It seems that it should be read as

    Appending is required for RollingFileAppender. Setting append=true.

    You can check the source code and see that appending will always be turned on. To get rid of the unwanted WARN/ERROR logs remove the <append> element from your configuration as the message hints.