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

When KafkaAppender is used with other KafkaProducer, there is a problem.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Critical
    • Resolution: Unresolved
    • 2.11.0
    • None
    • Appenders
    • None
    • scala 2.12.6 
      kafka 1.1.0 
      log4j2 2.11.0

    Description

      hi:

      When i use the log4j2's KafkaAppender , I found a bug.  the property CONFIG of the ProducerConfig is null.

      here's my code:

      log4j2.xml

      <Appenders>
          <Kafka name="Kafka" topic="test" key ="KafkaTestKey">
              <PatternLayout pattern="%d{yyyy.MM.dd 'at' HH:mm:ss z} %-5level %class{36} %L %M - %msg%xEx%n"/>
              <Property name="bootstrap.servers">localhost:9092</Property>
          </Kafka>
      </Appenders>
      

      the main class:

      object KafkaTest extends App {
        // this is scala code.
        // create a KafkaProducer
        val p = new Producer
      }
      
      

      producer code:

      class Producer {
        val props = {
          val p = new Properties()
          ....
          p
        }
      
        val producer = {
          val p = new KafkaProducer[Integer, String](props)
          p
        }
      }
      

      The reason for this BUG is that:  the `new Producer` is first initialized, and the `ProducerConfig` has a static method block, and it called the `CommonClientConfigs` class. in the `CommonClientConfigs` class,  it has a static Log property, so, this will initialize the Log4j2's configuration, and this will call a startup method of the Appender, it actually calls the KafkaAppender's method. and then the method create a new `KafkaProducer`, this will create a new `ProducerConfig` instance, but the static method block is not completed, so the `CONFIG` is null.  this cause the `NullPointerException`  

      my english is bad, so , hope to understand what i mean

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            Garbage_Y zhangjk
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: