我尝试使用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在其他地方使用?
答案 0 :(得分:1)
你能试试最新版本吗?我使用了最新版本,上面的条件语句工作得很好