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 "Remko Popma (JIRA)" <ji...@apache.org> on 2016/02/24 04:04:18 UTC

[jira] [Comment Edited] (LOG4J2-1296) Add MessageFactory that reuses a cached Message instance

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

Remko Popma edited comment on LOG4J2-1296 at 2/24/16 3:03 AM:
--------------------------------------------------------------

I just realized I'm not gracefully handling one of the misconfiguration cases: the case when Constants.ENABLE_THREADLOCALS is true but Loggers are not all asynchronous (Log4jContextSelector is not set to org.apache.logging.log4j.core.async.AsyncLoggerContextSelector). 

This is a problem because the Message will be reused, so it cannot be safely passed off to other threads like the AsyncAppender or the Disruptor for configurations where some loggers are synchronous and some are asynchronous. (Combining asynchronous logging with Log4jLogEvents containing reused Messages.)

I see two options:
* Handle reused Messages: build similar logic in Log4jLogEvent to what currently exists in RingBufferLogEvent (dealing with copying the message text if the specified Message is reused)
* Avoid creating reusable Messages: disable the ReusableParameterizedMessageFactory and only use the "normal" ParameterizedMessageFactory if Log4jContextSelector is not set to org.apache.logging.log4j.core.async.AsyncLoggerContextSelector.


was (Author: remkop@yahoo.com):
I just realized I'm not gracefully handling one of the misconfiguration cases: Constants.ENABLE_THREADLOCALS is true but Loggers are not all asynchronous (Log4jContextSelector is not set to org.apache.logging.log4j.core.async.AsyncLoggerContextSelector). 

> Add MessageFactory that reuses a cached Message instance
> --------------------------------------------------------
>
>                 Key: LOG4J2-1296
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1296
>             Project: Log4j 2
>          Issue Type: New Feature
>          Components: API
>    Affects Versions: 2.5
>            Reporter: Remko Popma
>            Assignee: Remko Popma
>
> As discussed in LOG4J2-1270, all current MessageFactory implementations create new temporary Message objects. A GC-free configuration needs a different MessageFactory that reuses Message instances.
> When Messages are being reused, async logging components need to be aware of this and ensure the Message _content_  (rather than the Message instance itself) is passed to the background thread. However, Messages that are not reusable should be passed to the background thread unchanged.



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

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org