spring-boot - Logback:测试属性是否已定义

标签 spring-boot logging logback spring-logback

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

相关文章:

logging - 在 GO 中滚动日志文件的最佳方式

java - logback不打印方法名称

spring-mvc - Spring Boot - 部署为 WAR 时从 WEB-INF/文件夹加载 'logback.xml'

java - 如何在@Async void 方法中断言异常?

java - Spring:获取特定接口(interface)和类型的所有 Bean

java - 仅设置拦截器关闭端点

java - Spring Boot新建项目时pom.xml报错

nginx limit_req_log_level - 日志在哪里?

logging - 使用不带日志的 systemd

java - Logback 不显示堆栈跟踪