Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-2341

JsonLayout not working with AsyncLoggerContextSelector in 2.11.0

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.11.0
    • Fix Version/s: 3.0.0, 2.11.1
    • Component/s: None
    • Labels:
      None

      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

            Activity

              People

              • Assignee:
                ckozak Carter Kozak
                Reporter:
                f-morozov Fedor Morozov
              • Votes:
                2 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: