![]() |
VOOZH | about |
SLF4J means that Simple Logging Facade for Java serves as a logging facade, allowing applications to use various logging frameworks such as Log4j, and Logback without being tied to a specific implementation Kafka, being a distributed streaming platform, also on SLF4J for its logging and Log4j has the written for the purpose print the messages.
This allows applications to use different logging implementations such as Log4j, and Logback without being tied to a specific one. Kafka is a distributed streaming platform also on SLF4j for its logging.
In this article, we will discuss how to disable SLF4J Logging in Apache Kafka.
Here it is the Example of the SLF4J - API dependency from the Kafka-clients Maven dependency.
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<version>2.0.0</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
And add the SLF4J- API dependency with the version we want to use.
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.30</version>
</dependency>
Here if we are using a logging framework that is built on top of SLF4J, such as Logback or Log4j we will also need to exclude the corresponding dependency from the Kafka-clients Maven dependency and add the version we want to use.
Here is the complete Maven Dependency for Disabling Kafka Logging:
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<version>2.0.0</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.30</version>
</dependency>
In this, exclude the slf4j-api dependency from the kafka-clients Maven dependency and add the slf4j-log4j12 binding library in our classpath. This will ensure that SLF4J logs through Log4j and we will not see any logging from Apache Kafka.
By setting the below properties in log4j.properties file we can also disable SLF4J Logging in Apache Kafka.
# Set log levels
log4j.rootLogger=ERROR, stdout
# Kafka logging
log4j.logger.org.apache.kafka=ERROR
# Redirect Kafka logging to 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
# Disable SLF4J logging
log4j.logger.org.slf4j=OFF
log4j.logger.org.apache.kafka.common.utils.AppInfoParser=OFF