2

我正在尝试使用 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 在其他任何地方使用?

4

1 回答 1

1

可以试试最新版本吗?我使用了最新版本,上面的条件语句工作得很好

于 2015-02-18T06:59:32.097 回答