Description
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:
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"); } }
<?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>
Without AsyncLoggerContextSelector the log looks like this:
"" ""
Without AsyncLoggerContextSelector:
{ "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 }
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:
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"
Attachments
Issue Links
- duplicates
-
LOG4J2-2312 Using async appender with json layout causes only the message to be written
- Resolved
- links to