我已经成功地用一个Log4J文件配置了log4j2.xml 2,并且正在通过JNDI变量查找成功地设置文件中Property的值。
但是,如果JNDI变量不存在,我希望为Property提供一个默认值。
这个是可能的吗?
发布于 2017-07-27 03:28:40
试试这个:
<Root level="${jndi:yourJndiVariableName:-DEFAULT}">通常,所有Log4j2查找都遵循以下模式:${type:key:-defaultValue}。
发布于 2017-07-26 19:08:39
是的:这可以通过使用默认的属性映射来完成:
<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>根据用于属性替换的Log4J 2配置文档,这也适用于其他属性来源(如环境变量、系统属性等)。
https://stackoverflow.com/questions/45335282
复制相似问题