logback 配置中的条件

conditions in logback configuration

我正在尝试使用 janino 的条件处理删除冗余的 logback 配置文件。

下面是我添加的条件逻辑

<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>

但这会引发以下错误

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]]

如果我删除条件逻辑并使用类似

的东西,配置工作正常
<root level="INFO">     
    <appender-ref ref="ROLLING" />
    <appender-ref ref="CONSOLE" />
    <appender-ref ref="EMAIL" />        
</root>

我如何正确配置它,使 CONSOLE appender 仅用于 Windows 而 EMAIL appender 用于其他任何地方?

你能试试最新版本吗?我使用的是最新版本,上面的条件语句工作得很好