[
https://issues.apache.org/jira/browse/LOG4J2-763?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14084230#comment-14084230
]
Remko Popma commented on LOG4J2-763:
------------------------------------
True, Messages need to be careful to either cache the formatted message, or the
parameters needed to create a formatted message when requested.
I don't mind calling {{getFormattedMessage}} on the log event before passing it
to the async background thread. Currently neither AsyncLoggers nor
AsyncAppenders do this, but this can easily be changed.
We still need to modify a few Message implementations to make sure that they
cache the formatted message rather than recalculating it from scratch every
time {{getFormattedMessage}} is called.
On a related note: the {{formattedMessage}} field is marked as {{transient}} in
a number of Message implementations. This may cause issues unless they also
cache the parameters in a non-transient String[] array and
{{getFormattedMessage}} uses the String[] parameters and not the original
Object[] parameters.
> 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]