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 "Oliver Flege (JIRA)" <ji...@apache.org> on 2013/10/08 20:06:43 UTC

[jira] [Updated] (LOG4J2-418) Support default value for missing key in map-based pattern

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

Oliver Flege updated LOG4J2-418:
--------------------------------

    Attachment: log4j2-418.patch

the patch uses ":-" to separate a key and the default value (similar to what slf4j/logback) does, so a pattern like %K{foo:-bar} would render bar if foo is not contained in the map.

> Support default value for missing key in map-based pattern
> ----------------------------------------------------------
>
>                 Key: LOG4J2-418
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-418
>             Project: Log4j 2
>          Issue Type: Improvement
>            Reporter: Oliver Flege
>            Priority: Minor
>         Attachments: log4j2-418.patch
>
>
> %X{key} and %K{key} render the value found for key in the thread context map or MapMessage, respectively. If the key is not contained in the map, the pattern evaluates to "" (empty string).   
> A default value for missing values can currently only be defined by using $${ctx:key} and defining a property named "key" with the desired default value. Drawbacks: ${ctx:key} has to be parsed and evaluated for each message and the pattern does not support conversion specifiers (for alignment, fixed width, etc). 
> The proposed improvement would be to support an optional default value that can be specified in the pattern, e.g. %X{key:-defaultValue}   



--
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