在 Spring Boot/Logback 项目中,我想检查系统属性是否设置为使用给定的附加程序。我的代码是:
<property name="MY_PROPERTY" value="${MY_PROPERTY:-}" />
....
<logger name="com.my.project" level="INFO">
<if condition='property("MY_PROPERTY").equalsIgnoreCase("MY_PROPERTY_IS_UNDEFINED")'>
<then>
<appender-ref ref="STDOUT" />
</then>
<else>
<appender-ref ref="APPENDER_WITH_ MY_PROPERTY" />
</else>
</if>
</logger>
上面的代码(似乎)有效,但这并不好。 property() 方法将 _IS_UNDEFINED 附加到变量名称,我使用它......
我找不到任何可靠的文档,有更好的方法吗?
最佳答案
聚会迟到了,但是嘿。
logback 手册 ( http://logback.qos.ch/manual/configuration.html ) 提到了 isDefined
方法:
The isDefined() method can be used to check whether a property is defined. For example, to check whether the property "k" is defined you would write isDefined("k") Similarly, if you need to check whether a property is null, the isNull() method is provided. Example: isNull("k").
关于spring-boot - Logback:测试属性是否已定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55138738/