简体   繁体   中英

How to disable loggers from class or a package which is from external jar

External jar selenium-server-2.42.2 is included to my java project. I want to disable the logging from some of the classes of this external jar I added below line in log4j.properties file

log4j.logger.org.openqa.selenium.remote.RemoteWebDriver=OFF

But still logs are displayed on a console as below

13:08:36.283 INFO - Executing: [find elements: By.xpath: //div[contains(@class,'loading-spinner')]])

Create a log4j.xml file to override the defaults in the 3rd party jar (an .xml file overrites property files). Here is an example:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration>
<appender name="console" class="org.apache.log4j.ConsoleAppender">
    <layout class="org.apache.log4j.PatternLayout">
    <param name="ConversionPattern" 
      value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n" />
    </layout>
</appender>

<category name="PACKAGE_TO_DISABLE">
    <priority value="off"/>
</category>

<root>
    <level value="DEBUG" />
    <appender-ref ref="console" />
</root>

In your case the package could be org.openqa.selenium! Or you have to try some values to get the right package!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM