You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by "Woonsan Ko (JIRA)" <ji...@apache.org> on 2013/10/21 05:07:42 UTC

[jira] [Updated] (LOG4J2-419) Support default value for missing key in look ups with fallbacking to looking in the properties map

     [ https://issues.apache.org/jira/browse/LOG4J2-419?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Woonsan Ko updated LOG4J2-419:
------------------------------

    Attachment: LOG4J2-419-patch.txt

Posting a patch (LOG4J2-419-patch.txt).

Basically, with this patch, we can append default value for a variable after the delimiter (the default delimiter is ':-'. The delimiter is customizable. See StrSubstitutor's setters).
For example,
{code}
${var1:-defval1},
${jndi:var2:-defval2}
{code}

The basic usages are shown and tested in the following unit tests:
- StrSubstitutorTest.java and XMLLoggerPropsTest.java

Also, RoutingAppenderWithJndiTest has been improved to show another default value setting example. This example can be used in the scenario where you want to leave log files per each web application by setting different JNDI context variable in each web application. Because we can use the JNDI context variable with default value, we don't have to even define multiple routes in this kind of use cases, but we can define single route with the variable and default value to leave separate logs for each web application.

By the way, the log4 configuration (log4j-loggerprops.xml) for XMLLoggerPropsTest.java also has a (global) property as well which have been used and is still working to define a default value.
The default value can be defined by *either* (global) property or inline default value after the delimiter.

If you have both (global) property and inline default value to specify default value for a variable, then the (global) property has precedence currently because the (global) property is used in StrLookup. The precedence order might be debatable later, but this seems okay to me for now.

Please review the patch.

Cheers,

Woonsan

> Support default value for missing key in look ups with fallbacking to looking in the properties map
> ---------------------------------------------------------------------------------------------------
>
>                 Key: LOG4J2-419
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-419
>             Project: Log4j 2
>          Issue Type: Improvement
>            Reporter: Woonsan Ko
>            Priority: Minor
>         Attachments: LOG4J2-419-patch.txt
>
>
> It is more useful and flexible to allow default value in the variable expression itself.
> For example, ${var1:-defvalue1}, ${ctx:request_id:-defvalue2}, etc.
> This generic feature has been included in StrSubstitutor of commons-lang3 as well with the following issue:
> - https://issues.apache.org/jira/browse/LANG-893
> The benefit from the feature with LANG-893 is we can use it more widely whenever used in look ups.



--
This message was sent by Atlassian JIRA
(v6.1#6144)

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org