[
https://issues.apache.org/jira/browse/LOG4J2-763?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14084194#comment-14084194
]
Remko Popma commented on LOG4J2-763:
------------------------------------
Ralph, I think ParameterizedMessage is already okay; its constructor accepts an
Object[] array, and creates a String[] array by calling the {{deepToString}}
method on each of the elements of the object parameter array. This happens in
the constructor, so in the application thread, not in the async background
thread. The {{ParameterizedMessage.getFormattedMessage}} method called by the
background thread uses the resulting String[] array.
So ParameterizedMessage already takes a String snapshot of each of the
parameters when the message is constructed.
Similar logic probably needs to be added to:
* ObjectMessage
* FormattedMessage
* LocalizedMessage
* MapMessage (hmm... this Message is mutable by design it seems. That may be a
problem...)
* StringFormattedMessage
* StructuredDataMessage (subclass of MapMessage, also mutable)
> 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]