Search code examples
javaloggingjndilog4j2

How do I set a default value when looking up a JNDI variable lookup with Log4J 2?


I'm already successfully configuring Log4J 2 with a log4j2.xml file, and I'm successfully setting the value of a Property in the file via a JNDI variable lookup.

However, I'd like to provide a default value for the Property if the JNDI variable doesn't exist.

Is this possible?


Solution

  • Try this:

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

    Generally all Log4j2 lookups follow this pattern: ${type:key:-defaultValue}.