Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we disable log4j logs only for kafka

i am using following log4j.properties

log4j.rootLogger=DEBUG, stdout


log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

I wanted to disable log messages for kafka only. where as display my log messages being logged.

like image 464
babravahan Avatar asked May 24 '18 12:05

babravahan


People also ask

Does Kafka use log4j?

Kafka Connect and other Confluent Platform components use the Java-based logging utility Apache Log4j to collect runtime data and record component events.

How do you stop Kafka logs?

Alter EXTRA_ARGS for the Kafka service variable to disable GC Logging. Alter EXTRA_ARGS for the ZooKeeper service variable to disable GC Logging. It's as simple as that.

Is Kafka used for logging?

Kafka can serve as a kind of external commit-log for a distributed system. The log helps replicate data between nodes and acts as a re-syncing mechanism for failed nodes to restore their data. The log compaction feature in Kafka helps support this usage. In this usage Kafka is similar to Apache BookKeeper project.


2 Answers

you need to disable logger for both log4j and slf4j to disable kafka logging completely:

Add a logback.xml file in your resources dir:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <include resource="org/springframework/boot/logging/logback/base.xml" />
    <logger name="org.springframework" level="OFF"/>
    <logger name="org.apache" level="OFF"/>
    <logger name="kafka" level="OFF"/>
</configuration>

Add below to your application.yaml / properties:

logging:
  level:
    root: OFF
    org.springframework: OFF
    org.apache: OFF
    kafka: OFF
like image 96
Dean Jain Avatar answered Sep 17 '22 16:09

Dean Jain


You need to set the log level to OFF by adding this line:

log4j.logger.org.apache.kafka=OFF

Compare: How to disable loggers of a class or of whole package?

like image 21
Matthias J. Sax Avatar answered Sep 16 '22 16:09

Matthias J. Sax