Can we disable log4j logs only for kafka

风格不统一 提交于 2020-06-27 10:35:30

问题


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.


回答1:


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?




回答2:


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


来源:https://stackoverflow.com/questions/50509743/can-we-disable-log4j-logs-only-for-kafka

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!