How to disable log4j in 3rd party jar?

前端 未结 3 1589
梦如初夏
梦如初夏 2021-01-01 18:03

I\'m experimenting writing a java SE swing application using JBoss weld. Weld configures logging with log4j using the following log4j.xml file in the jar:

&l         


        
相关标签:
3条回答
  • 2021-01-01 18:03

    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.

    0 讨论(0)
  • 2021-01-01 18:04

    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.

    0 讨论(0)
  • 2021-01-01 18:28

    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>
    
    0 讨论(0)
提交回复
热议问题