Can't turn off HtmlUnit logging messages

后端 未结 7 2048
悲哀的现实
悲哀的现实 2020-12-28 08:50

I\'m using HtmlUnit to interact with a web page that interacts with the server via Ajax. Soon after the Ajax code starts, HtmlUnit produces these two log messages:

7条回答
  •  粉色の甜心
    2020-12-28 09:04

    I too had issues with this.. The answer depends on what logging system commons-logging is using under the hood. (since common-logging is just a wrapper). See the following http://commons.apache.org/proper/commons-logging/guide.html#Configuring_The_Underlying_Logging_System

    The attribute you mention above (org.apache.commons.logging.simplelog.defaultlog) should only be valid if the simple logger is been used. If you are running on JDK 1.4 or higher however it should default to using the JDK logging. In which case it defaults to using the lib/logging.properties from the JRE install location.

    In my case I had Log4j in the classpath, so it defaulted to that.

    To take away the randomness of all this you can explicitly set the Logger yourself. Create a commons-logging.properties file in the classpath and pass in the logger to use e.g.

    # JDK Logging
    #org.apache.commons.logging.Log=org.apache.commons.logging.impl.Jdk14Logger
    # Log4j logging (also required log4j.jar to be in classpath)
    org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger
    

    For log4j, adding the following the log4j.properties stops the warnings from HtmlUnit.

    log4j.logger.com.gargoylesoftware.htmlunit=ERROR
    

提交回复
热议问题