title: How to change the Kafka client logging levels/preferences?
body: <p>I am using a plain Java project to run (no framework) a Kafka producer and a consumer.</p>
  
  <p>I am trying to control the logs generated by the <code>KafkaProducer</code> and <code>KafkaConsumer</code> code and I cannot influence it using the <code>log4j.properties</code> configuration:</p>
  
  <pre><code>log4j.rootLogger=ERROR,stdout
  
  log4j.logger.kafka=ERROR,stdout
  log4j.logger.org.apache.kafka.clients.producer.ProducerConfig=ERROR,stdout
  log4j.logger.org.apache.kafka.common.utils.AppInfoParser=ERROR,stdout
  log4j.logger.org.apache.kafka.clients.consumer.internals.AbstractCoordinator=ERROR,stdout
  
  log4j.appender.stdout=org.apache.log4j.ConsoleAppender
  log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
  log4j.appender.stdout.layout.ConversionPattern=[%d] %p %m (%c)%n
  </code></pre>
  
  <p>Still I get log output like the one below, whatever settings I provide in the <code>log4j.properties</code> file:</p>
  
  <pre><code>[main] INFO org.apache.kafka.clients.producer.ProducerConfig - ProducerConfig values:
  ...
  [main] INFO org.apache.kafka.clients.producer.ProducerConfig - ProducerConfig values:
  ...
  [main] INFO org.apache.kafka.clients.producer.ProducerConfig - ProducerConfig values:
  ...
  [main] INFO org.apache.kafka.clients.consumer.internals.AbstractCoordinator - [Consumer clientId=UM00160, groupId=string-group] (Re-)joining group
  </code></pre>
  
  <p>How can I control the logging of the Kafka clients library? What am I missing to link my <code>log4j.properties</code> file to the Kafka clients library logging? In order not to spam the output I have to run Maven test using: <code>mvn test 2&gt; /dev/null</code>. Can I configure this via the <code>log4j.properties</code>.</p>
  
  <p><strong>Context:</strong></p>
  
  <p>I have the following relevant files:</p>
  
  <pre><code>── test
     ├── java
     │   └── com
     │       └── example
     │           ├── PropertyReader.java
     │           └── strings
     │               └── TestKafkaStringValues.java
     └── resources
         ├── application.properties
         └── log4j.properties
  </code></pre>
  
  <p>And I am trying to run the <code>TestKafkaStringValues.java</code> both using the Maven surefire plugin (<code>mvn test</code>) or the Eclipse JUnit plugin (equivalent to <code>java ...</code>).</p>
  
  <p>For surefire I use the following configuration in the Maven <code>pom.xml</code>:</p>
  
  <pre><code>&lt;plugin&gt;
      &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
      &lt;version&gt;2.22.2&lt;/version&gt;
      &lt;configuration&gt;
          &lt;systemPropertyVariables&gt;
              &lt;log4j.configuration&gt;file:log4j.properties&lt;/log4j.configuration&gt;
          &lt;/systemPropertyVariables&gt;
      &lt;/configuration&gt;
  &lt;/plugin&gt;
  </code></pre>
  
  <p>and for JUnit I use the following Java VM argument: <code>-Dlog4j.configuration=log4j.properties</code>.</p>
  
  <p>I also tried in both cases to use the absolute path to <code>log4j.properties</code>. Still not working.</p>
  
  <p>You can see the complete code <a href="https://github.com/gabipetrovay/avro-tests/tree/575f39c9e7751f1316ac2cdb3088220dd9528345" rel="nofollow noreferrer">here</a>.</p>