[ 
https://issues.apache.org/jira/browse/LOG4J2-2392?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16680446#comment-16680446
 ] 

Som Snytt commented on LOG4J2-2392:
-----------------------------------

To clarify, ParameterizedMessage counts the paired-brace placeholders in the 
message string, and if the throwable arg is consumed by a placeholder, it is 
formatted and not retained for later layout.

This is very confusing API.

{{logger.error("Failed with {}", e);}}
{{logger.error("The {} failed with {}", thing, e);}}

The workaround is to cast to select the desired overload, which works with both 
current and older versions of the interface:

{{logger.error("Failed with {}", (Object) e);}}

Arguably, since ParameterizedMessage will retain the exception if it is not 
consumed in formatting, the (String, Throwable) method could just forward, so 
that it is incumbent upon the Message implementation to preserve this behavior.

> Throwable param is not handled as rendering param
> -------------------------------------------------
>
>                 Key: LOG4J2-2392
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-2392
>             Project: Log4j 2
>          Issue Type: Bug
>    Affects Versions: 2.11.0
>            Reporter: Fuud
>            Priority: Minor
>
> This code:
> {code}
> import org.slf4j.Logger;
> import org.slf4j.LoggerFactory;
> public class Test {
>     public static void main(String[] args) {
>         Logger logger = LoggerFactory.getLogger("abc");
>         Exception e = new Exception();
>         logger.error("Failed with {}", e);
>     }
> }
> {code}
> Outputs:
> {code}
> [main] ERROR abc - Failed with {}
> java.lang.Exception: null
>       at Test.main(Test.java:7)
> {code}
> But expected that Exception will be used in message rendering:
> {code}
> [main] ERROR abc - Failed with java.lang.Exception: null
> java.lang.Exception: null
>       at Test.main(Test.java:7)
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to