2017-07-26 78 views

回答

1

試試這個:

<Root level="${jndi:yourJndiVariableName:-DEFAULT}"> 

一般來說,所有Log4j2查找遵循這個模式:${type:key:-defaultValue}

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,這也將爲其他財產來源(如環境變量,系統屬性等)工作。