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

Remko Popma edited comment on LOG4J2-1280 at 2/19/16 4:26 AM:
--------------------------------------------------------------

Taking a long hard look at my own work from last night :-) I see I made a 
mistake.

{code}
protected void logMessage(final String fqcn, final Level level, final Marker 
marker, 
        final Supplier<?> msgSupplier, final Throwable t) {

    // This is wrong: 
    // LamdaUtil detects if the supplied object is a Message,
    // and prevents that Message from being wrapped in another message
    // (this is good).
    // However, we want to log the _supplied_ Message here, instead of
    // creating a new message for the formattedString of the supplied Message.
    final Object message = LambdaUtil.get(msgSupplier);
    logMessage(fqcn, level, marker, messageFactory.newMessage(message), t);
}
{code}


was (Author: [email protected]):
Taking a long hard look at my own work from last night I see I made a mistake.

{code}
protected void logMessage(final String fqcn, final Level level, final Marker 
marker, 
        final Supplier<?> msgSupplier, final Throwable t) {

    // This is wrong: 
    // LamdaUtil detects if the supplied object is a Message,
    // and prevents that Message from being wrapped in another message
    // (this is good).
    // However, we want to log the _supplied_ Message here, instead of
    // creating a new message for the formattedString of the supplied Message.
    final Object message = LambdaUtil.get(msgSupplier);
    logMessage(fqcn, level, marker, messageFactory.newMessage(message), t);
}
{code}

> Logger methods taking Supplier<?> parameters should check if supplied value 
> is Message
> --------------------------------------------------------------------------------------
>
>                 Key: LOG4J2-1280
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1280
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: API
>    Affects Versions: 2.5
>            Reporter: Remko Popma
>            Assignee: Remko Popma
>             Fix For: 2.6
>
>
> Methods on the Logger interface that take a Supplier<?> argument currently do 
> not correctly handle the case where the supplied value is of type Message.
> Currently, either the Message value will be wrapped in an ObjectMessage, or 
> it will be used as one of the parameter values in a parameterized text 
> message. In both cases, the result of Message.toString() will eventually be 
> logged, rather than Message.getFormattedString().



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to