[ 
https://issues.apache.org/jira/browse/LOG4J2-1424?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Remko Popma updated LOG4J2-1424:
--------------------------------
    Description: 
In non-garbage-free mode, the logged Message objects are immutable and can be 
simply passed on to the background thread as part of the LogEvent.

In garbage-free mode each application thread reuses a mutable message, and 
transfers the message content into the AsyncLogger ringbuffer for consumption 
by the background thread. 

[RingBufferLogEvent|http://logging.apache.org/log4j/2.x/log4j-core/xref/org/apache/logging/log4j/core/async/RingBufferLogEvent.html#L115]
 and 
[MutableLogEvent|http://logging.apache.org/log4j/2.x/log4j-core/xref/org/apache/logging/log4j/core/impl/MutableLogEvent.html#L192]
 have fields and code to deal with transferring data out of the reused message 
into the event, but this is specific to parameterized text messages.

This ticket proposes to make this mechanism more general so it can be used by 
custom messages. 

* Define interface RingBufferMessage with one method {{initFrom(Message)}}
* Define interface RingBufferMessageFactory
* Current log4j behaviour can be encapsulated in a DefaultRingBufferMessage and 
a DefaultRingBufferMessageFactory class.
 
*Ringbuffer initialization*
When the ringbuffer is created, each of the pre-allocated log events must also 
be assigned a RingBufferMessage object capable of receiving message content. 
For custom Messages, one way to let users control this is to let users specify 
a RingBufferMessageFactory for these RingBufferMessage objects. For example, 
the current RingBufferLogEvent and MutableLogEvent fields {{message}}, 
{{messageText}}, {{parameters}} and {{parameterCount}} can be encapsulated in a 
DefaultRingBufferMessage, and Log4j can define a 
DefaultRingBufferMessageFactory.

*Enqueueing a message*
When a Message is enqueued in the ringbuffer, the 
RingBufferMessage#initFrom(Message) method will be called. The 
RingBufferMessage implementation knows how to obtain the payload data from the 
logged Message. For the current text messages that is the {{setMessage}} code 
currently defined in RingBufferLogEvent and MutableLogEvent. A user-defined 
RingBufferMessage that deals with custom Messages can define its own 
implementation.

  was:
Log4j 2.6 in garbage-free mode uses a reusable message, and transfers the 
message content into the AsyncLogger ringbuffer for consumption by the 
background thread. 

This ticket proposes to make this mechanism more general so it can be used by 
custom messages. 

This will involve 
* Some way for users to populate the ringbuffer with either custom 
RingBufferLogEvents, or by setting the Message field of the RingBufferLogEvents 
to pre-allocated instances.
* Some transfer mechanism to copy the payload of a custom Message that was 
logged by the appliction into the Message field of the RingBufferLogEvent


> Generic Message contents transfer mechanism into Async Logger ringbuffer
> ------------------------------------------------------------------------
>
>                 Key: LOG4J2-1424
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1424
>             Project: Log4j 2
>          Issue Type: Improvement
>          Components: Core
>    Affects Versions: 2.6
>            Reporter: Remko Popma
>
> In non-garbage-free mode, the logged Message objects are immutable and can be 
> simply passed on to the background thread as part of the LogEvent.
> In garbage-free mode each application thread reuses a mutable message, and 
> transfers the message content into the AsyncLogger ringbuffer for consumption 
> by the background thread. 
> [RingBufferLogEvent|http://logging.apache.org/log4j/2.x/log4j-core/xref/org/apache/logging/log4j/core/async/RingBufferLogEvent.html#L115]
>  and 
> [MutableLogEvent|http://logging.apache.org/log4j/2.x/log4j-core/xref/org/apache/logging/log4j/core/impl/MutableLogEvent.html#L192]
>  have fields and code to deal with transferring data out of the reused 
> message into the event, but this is specific to parameterized text messages.
> This ticket proposes to make this mechanism more general so it can be used by 
> custom messages. 
> * Define interface RingBufferMessage with one method {{initFrom(Message)}}
> * Define interface RingBufferMessageFactory
> * Current log4j behaviour can be encapsulated in a DefaultRingBufferMessage 
> and a DefaultRingBufferMessageFactory class.
>  
> *Ringbuffer initialization*
> When the ringbuffer is created, each of the pre-allocated log events must 
> also be assigned a RingBufferMessage object capable of receiving message 
> content. For custom Messages, one way to let users control this is to let 
> users specify a RingBufferMessageFactory for these RingBufferMessage objects. 
> For example, the current RingBufferLogEvent and MutableLogEvent fields 
> {{message}}, {{messageText}}, {{parameters}} and {{parameterCount}} can be 
> encapsulated in a DefaultRingBufferMessage, and Log4j can define a 
> DefaultRingBufferMessageFactory.
> *Enqueueing a message*
> When a Message is enqueued in the ringbuffer, the 
> RingBufferMessage#initFrom(Message) method will be called. The 
> RingBufferMessage implementation knows how to obtain the payload data from 
> the logged Message. For the current text messages that is the {{setMessage}} 
> code currently defined in RingBufferLogEvent and MutableLogEvent. A 
> user-defined RingBufferMessage that deals with custom Messages can define its 
> own implementation.



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

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

Reply via email to