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

Ralph Goers commented on LOG4J2-763:
------------------------------------

Well, I still have misgivings about this approach as it means that Messages 
have to be very careful how they are constructed, but it looks to me like it 
would work.

In the case of MapMessage, if it is not a SortedMap it is copied into one. We 
could just always copy it. Since it is a Map<String, String> it can still be 
manipulated but I think it is OK to allow updates to the Map associated with 
the Message as that should only be done in special cases within the logging 
system. FWIW, I am doing that in one of my projects in a LoggerWrapper.  We 
just need to document what is thread safe and what isn't.



> Async loggers convert message parameters toString at log record writing not 
> at log statement execution
> ------------------------------------------------------------------------------------------------------
>
>                 Key: LOG4J2-763
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-763
>             Project: Log4j 2
>          Issue Type: Bug
>    Affects Versions: 2.0
>            Reporter: Stephen Connolly
>
> http://javaadventure.blogspot.com/2014/07/log4j-20-async-loggers-and-immutability.html
> TL;DR When using parameterized messages, the toString() method of the log 
> messages is not called when the log message is enqueued, rather after the log 
> message has been dequeued for writing. If any of the message parameters are 
> mutable, they can thus have changed state before the log message is written, 
> thus resulting in the logged message content being incorrect.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

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

Reply via email to