how to change log levels of 3rd party library in java

浪子不回头ぞ 提交于 2019-12-24 09:05:31

问题


The console logs is cluttered with logs from 3rd part libraries. For example my project uses kafka and zooker keeper client libraries because of this there are too many logs from them

  1. 2018-05-08 10:30:38.250 INFO 2968 --- [0:0:0:0:1:2181)] org.apache.zookeeper.ClientCnxn : Opening socket connection to server 0:0:0:0:0:0:0:1/0:0:0:0:0:0:0:1:2181. Will not attempt to authenticate using SASL (unknown error)

  2. 2018-05-08 10:30:38.309 INFO 2968 --- [ main] o.a.k.clients.producer.ProducerConfig : ProducerConfig values:

    there is a log4j2.xml file in my project. Changing root log level in xml file only changes log level of the custom logs generated by my project. Is there a way to stop or changes logs of these libraries


回答1:


Switch to Logback and change the logging level for flooding logger. Usually, it names after its class reference.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
 <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
        <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
    </encoder>
 </appender>
 <logger name="flooding logger" level="ERROR" additivity="false">
    <appender-ref ref="STDOUT"/>
 </logger>
 <root level="INFO">
    <appender-ref ref="STDOUT"/>
 </root>
</configuration>


来源:https://stackoverflow.com/questions/50226224/how-to-change-log-levels-of-3rd-party-library-in-java

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