我已经使用log4j2.xml
文件成功配置了Log4J 2,并且我通过以下方式成功设置了文件Property
的值
JNDI variable lookup
但是,如果JNDI变量不存在,我想为Property
提供默认值。
这可能吗?
答案 0 :(得分:1)
试试这个:
<Root level="${jndi:yourJndiVariableName:-DEFAULT}">
通常所有Log4j2查找都遵循以下模式:${type:key:-defaultValue}
。
答案 1 :(得分:0)
是:可以使用默认属性映射来完成此操作:
<Configuration status="DEBUG" name="Example">
<Properties>
<Property name="yourJndiVariableName">
the value used if the JNDI variable cannot be found
</Property>
</Properties>
... more configuration ...
<Loggers>
<Root level="${jndi:yourJndiVariableName}">
<AppenderRef ref="console"/>
</Root>
</Loggers>
... more configuration ...
</Configuration>
According to the Log4J 2 configuration documentation for property substitution,这也适用于其他属性来源(例如环境变量,系统属性等)。