How do I turn logging off using log4j?

前端 未结 5 1250
独厮守ぢ
独厮守ぢ 2020-12-30 09:16

I am using a third-party library which has a log4j.xml configuration - what\'s the best way to turn off the logging?

相关标签:
5条回答
  • 2020-12-30 09:56

    With log4j.xml the minimal solution looks like this:

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

    Note that in threshold="off", "off" must be in lower case.

    0 讨论(0)
  • 2020-12-30 10:00

    Or directly from code:

    Logger.getRootLogger().removeAllAppenders();
    
    0 讨论(0)
  • 2020-12-30 10:03

    You could also try setting the logging level to "Severe" if you only want to log game-breaking events.

    0 讨论(0)
  • 2020-12-30 10:07

    Depends on configuration. Try something like:

    <log4j:configuration>
        <root>
            <priority value ="off" />
            <appender-ref ref="console" />
            <appender-ref ref="rolling-file" />
        </root>
    </log4j:configuration>
    

    Check Log4jXmlFormat for more details.

    0 讨论(0)
  • 2020-12-30 10:21

    I think all that is required is to set the threshold parameter to OFF

    <log4j:configuration threshold="OFF">
        <root>
            <priority value ="off" />
            <appender-ref ref="console" />
            <appender-ref ref="rolling-file" />
        </root>
    </log4j:configuration>
    
    0 讨论(0)
提交回复
热议问题