How to disable log4j in 3rd party jar?

半城伤御伤魂 提交于 2019-12-03 10:30:20

Shortly after posting this question I discovered the answer. Create a log4j.xml file to override the defaults in the 3rd party JAR.

Here is an example specific to this thread:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd" >
<log4j:configuration>

    <appender name="CA" class="org.apache.log4j.ConsoleAppender">
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%m%n"/>
        </layout>
    </appender>

    <!-- 
        If you want to enable logging for the application
        but wish to disable logging for a specific package
        then use this, where org.jboss is the package
        for which you wish to disable logging.
    -->
    <category name="org.jboss">
        <priority value="off"/>
    </category>

    <root>
        <priority value="off"/> <!--Notice this disables all logging-->
        <appender-ref ref="CA"/>
    </root>

</log4j:configuration>

I think the default log configuration for third part jars won`t print any message into STDOUT or FILE.

But if you want override the default log configuration without document, the best solution is de-compile the jar files and find out how it load the configuration.

If a log4j xml-format configuration file is present, it takes precedence over property files. That is log4j defined behavior. So you can put your configuration in log4j.xml and it should take effect.

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