In a Spring Boot / Logback project, I want to check if a system property is set to use a given appender or not. My code is:
<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>
The code above (seems to) works, but this is not nice. The property() method append _IS_UNDEFINED to the variable name and I use it...
I can't find any reliable documentation about it, is there a better way?
Late to the party, but hey.
The logback manual (http://logback.qos.ch/manual/configuration.html) mentions the isDefined
method:
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").
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With