You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by "Ralph Goers (JIRA)" <ji...@apache.org> on 2014/08/04 02:44:12 UTC

[jira] [Commented] (LOG4J2-763) Async loggers convert message parameters toString at log record writing not at log statement execution

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

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

Thanks Stephen.  

We actually read your blog and commented on it on the private list (along with a few other blogs mentioning Log4j 2).  Remko suggested that this may be solved by having SimpleMessage and ObjectMessage call toString() on the constructor argument. Since SimpleMessage takes a String already nothing probably needs to be done with it.

However, I am not sure it is that simple.  ParamterizedMessage takes an array of objects for substitution. These objects should not be passed to another thread or the same problem will result. So really, the Message's getFormattedMessage method really needs to be called and the result should be passed as part of the log event.

> 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: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org