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

Anthony Maire commented on LOG4J2-1397:
---------------------------------------

Correct me if I am wrong, but handling ByteBuffers at layout level will force 
the application code to make a defensive copy of the ByteBuffer to be 
compatible with asynchronous appenders/loggers (so either the application code 
needs to know how the logging will be configured or some potentially useless 
copy has to be done).

A common pattern is to have a DirectByteBuffer that is re-used (since direct 
buffers are costly to allocate and to collect) so that SocketChannel reads 
don't need to perform an additionnal copy. Then the raw message is logged 
before trying to process it. Being asynchronous in this use case is crucial 
since the flow can be pretty high (every message is logged) and the jitter when 
the kernel is flushing to disk can be very high and freeze the application 
critical path. This usecase will not be correcty managed by this approach:
=> When the layout is called, the content of the buffer may have change
=> If the application tries to process the message while the layout is 
"encoding", there will be a race condition on buffer position/limit fields. The 
same issue can occurs if the buffer can be logged by several appenders (even 
with a defensive copy in application code)





> Support ByteBufferLayout
> ------------------------
>
>                 Key: LOG4J2-1397
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1397
>             Project: Log4j 2
>          Issue Type: New Feature
>          Components: Layouts
>    Affects Versions: 2.6
>            Reporter: Remko Popma
>
> As requested by Kirk Pepperdine on the Mechanical Sympathy [mailing 
> list|https://groups.google.com/d/msg/mechanical-sympathy/klefjRqlpQE/-1WF59IGAwAJ]:
> Support a new Layout that takes ObjectMessages containing a ByteBuffer 
> payload and write them to the appender without modification.



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

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

Reply via email to