【问题标题】:conditions in logback configurationlogback 配置中的条件
【发布时间】:2015-02-18 14:59:32
【问题描述】:

我正在尝试使用 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 附加程序仅在 Windows 上使用,而 EMAIL 附加程序在其他任何地方使用?

【问题讨论】:

  • 你使用的 logback 库版本是多少?
  • logback 0.9.17 版和 slf4j 1.5.8 版
  • 可以试试最新版本吗?我使用了最新版本,上面的条件语句工作得很好
  • 谢谢。它适用于较新版本的 logback :-)
  • @AndyDufresne - 你能用同样的评论回答这个问题,以便我可以将其标记为已回答吗?

标签: logback janino


【解决方案1】:

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

【讨论】:

  • 即使对我来说,它也可以使用最新版本的 logback
猜你喜欢
  • 2018-05-18
  • 2016-06-09
  • 1970-01-01
  • 2012-12-14
  • 2023-03-30
  • 1970-01-01
  • 2017-07-11
  • 2016-04-25
相关资源
最近更新 更多