I am using a plain Java project to run (no framework) a Kafka producer and a consumer.
I am trying to control the logs generated by the KafkaProducer and KafkaConsumer code and I cannot influence it using the log4j.properties configuration:
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
Still I get log output like the one below, whatever settings I provide in the log4j.properties file:
[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
How can I control the logging of the Kafka clients library? What am I missing to link my log4j.properties file to the Kafka clients library logging? In order not to spam the output I have to run Maven test using: mvn test 2> /dev/null. Can I configure this via the log4j.properties.
Context:
I have the following relevant files:
── test
├── java
│ └── com
│ └── example
│ ├── PropertyReader.java
│ └── strings
│ └── TestKafkaStringValues.java
└── resources
├── application.properties
└── log4j.properties
And I am trying to run the TestKafkaStringValues.java both using the Maven surefire plugin (mvn test) or the Eclipse JUnit plugin (equivalent to java ...).
For surefire I use the following configuration in the Maven pom.xml:
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<systemPropertyVariables>
<log4j.configuration>file:log4j.properties</log4j.configuration>
</systemPropertyVariables>
</configuration>
</plugin>
and for JUnit I use the following Java VM argument: -Dlog4j.configuration=log4j.properties.
I also tried in both cases to use the absolute path to log4j.properties. Still not working.
You can see the complete code here.