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

Carter Kozak commented on LOG4J2-2341:
--------------------------------------

> That interface is documented as not being Thread safe

AbstractJacksonLayout doesn't require thread safety, so there's no reason for 
us to create memento objects. The problem is that its behavior is based on 
instanceof checks for Jackson serialization. While we don't need thread safety, 
we do need to make the LogEvent object not implement Message. In this PR 
(https://github.com/apache/logging-log4j2/pull/263), I wrote a very light 
weight wrapper type which simple wraps the delegate event without making a deep 
copy, which requires much less overhead than using Jackson.

> I don't think we want to test against Message

We provide a configuration point for custom LogEvent implementations, and a 
custom event which also implements Message would cause this case to fail 
because our jackson configuration checks for Message implementations before 
LogEvent.
I agree that nothing we ship would fail if we validated against ReusableMessage 
instead of Message, however I am not aware of any LogEvent implementations 
which implement Message and not ReusableMessage, so I don't think we have any 
reason to sacrifice correctness.

> JsonLayout not working with AsyncLoggerContextSelector in 2.11.0
> ----------------------------------------------------------------
>
>                 Key: LOG4J2-2341
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-2341
>             Project: Log4j 2
>          Issue Type: Bug
>    Affects Versions: 2.11.0
>            Reporter: Fedor Morozov
>            Assignee: Carter Kozak
>            Priority: Major
>             Fix For: 3.0.0, 2.11.1
>
>
> In version 2.11.0 appenders with JsonLayout don't output json when 
> Log4jContextSelector is set to 
> org.apache.logging.log4j.core.async.AsyncLoggerContextSelector.
> Here is a sample:
> {code:java}
> package ru.yandex.zen;
> import org.apache.log4j.Logger;
> public class LoggerSample {
>     public static void main(String[] args) {
>         Logger logger = Logger.getLogger("LoggerSample");
>         logger.info("Message 1");
>         logger.info("Message 2");
>     }
> }
> {code}
> {code:java}
> <?xml version="1.0" encoding="UTF-8"?>
> <Configuration status="WARN">
>     <Appenders>
>         <RandomAccessFile name="RandomAccessFile" fileName="async.log" 
> immediateFlush="false" append="false">
>             <JsonLayout/>
>         </RandomAccessFile>
>     </Appenders>
>     <Loggers>
>         <Root level="info">
>             <AppenderRef ref="RandomAccessFile"/>
>         </Root>
>     </Loggers>
> </Configuration>
> {code}
> Without AsyncLoggerContextSelector the log looks like this:
> {code:java}
> ""
> ""
> {code}
> Without AsyncLoggerContextSelector:
> {code:java}
> {
> "thread" : "main",
> "level" : "INFO",
> "loggerName" : "LoggerSample",
> "message" : "Message 1",
> "endOfBatch" : false,
> "loggerFqcn" : "org.apache.log4j.Category",
> "instant" : {
> "epochSecond" : 1527061940,
> "nanoOfSecond" : 637000000
> },
> "threadId" : 1,
> "threadPriority" : 5
> }
> {
> "thread" : "main",
> "level" : "INFO",
> "loggerName" : "LoggerSample",
> "message" : "Message 2",
> "endOfBatch" : false,
> "loggerFqcn" : "org.apache.log4j.Category",
> "instant" : {
> "epochSecond" : 1527061940,
> "nanoOfSecond" : 717000000
> },
> "threadId" : 1,
> "threadPriority" : 5
> }
> {code}
> In our main application Json logger outputs the provided message in quotes, 
> not just an empty string. The problem doesn't appear when using asyncRoot or 
> asyncLogger.
> My dependencies:
> {code:java}
> compile 'org.apache.logging.log4j:log4j-api:2.11.0'
> compile 'org.apache.logging.log4j:log4j-core:2.11.0'
> compile "org.apache.logging.log4j:log4j-1.2-api:2.11.0"
> compile "com.fasterxml.jackson.core:jackson-core:2.9.4"
> compile "com.fasterxml.jackson.core:jackson-databind:2.9.4"
> {code}
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to