[logback-user] conditions in logback configuration

Aneesh Joseph aneeshkj1987 at gmail.com
Wed Jan 7 08:13:08 CET 2015


Hi,

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

Below is the conditional logic which I had added within the configuration
tag (along with the appender details)

<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 when logback is initialized

12:30:34,877 |-ERROR in
ch.qos.logback.core.joran.spi.Interpreter at 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 at 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 at 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 at 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 at 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>

I have already added janino as a Maven dependency. 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?


Thanks,

Aneesh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20150107/f5d572d4/attachment.html>


More information about the Logback-user mailing list