logbackjanino

conditions in logback configuration


I'm trying to remove redundant logback config files by using janino's conditional processing.

Below is the conditional logic which I had added

<root level="INFO">     
    <appender-ref ref="ROLLING" />
    <!-- use console appender on windows, email appender on linux -->
    <if condition='property("os.name").contains("win")'>
        <then>
            <appender-ref ref="CONSOLE" />
        </then>
        <else>
            <appender-ref ref="EMAIL" />
        </else>
    </if>       
</root>

but this throws the below errors

12:30:34,877 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@90:55 - no applicable action for [if], current pattern is [[configuration][root][if]]
12:30:34,877 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@91:10 - no applicable action for [then], current pattern is [[configuration][root][if][then]]
12:30:34,877 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@92:35 - no applicable action for [appender-ref], current pattern is [[configuration][root][if][then][appender-ref]]
12:30:34,877 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@94:10 - no applicable action for [else], current pattern is [[configuration][root][if][else]]
12:30:34,877 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@95:35 - no applicable action for [appender-ref], current pattern is [[configuration][root][if][else][appender-ref]]

The configuration works fine if I remove the conditional logic and use something like

<root level="INFO">     
    <appender-ref ref="ROLLING" />
    <appender-ref ref="CONSOLE" />
    <appender-ref ref="EMAIL" />        
</root>

How can I configure this correctly in such a way that the CONSOLE appender is used only on Windows and the EMAIL appender everywhere else?


Solution

  • Can you try the latest version? I used the latest version and the above conditional statements work perfectly fine