how to turn off verbose reporting by htmlunit?
htmlunit reports everything from css, to parsing errors on a page.
how to silence this ??开发者_运维技巧
Put these after declaring webClient
webClient.setCssErrorHandler(new SilentCssErrorHandler());
LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog");
java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(Level.OFF);
java.util.logging.Logger.getLogger("org.apache.commons.httpclient").setLevel(Level.OFF);
java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter").setLevel(Level.OFF);
java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit.javascript.host.ActiveXObject").setLevel(Level.OFF);
java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDocument").setLevel(Level.OFF);
java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit.html.HtmlScript").setLevel(Level.OFF);
java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit.javascript.host.WindowProxy").setLevel(Level.OFF);
java.util.logging.Logger.getLogger("org.apache").setLevel(Level.OFF);
HTMLUnit uses Apache commons logging which delegates actual logging to a "real" logging framework, or the standard java one.
If your application uses log4j you can use that to reduce the chattiness of htmlunit.
More details can be found on the logging page of the docs
HTMLUnit uses standard JAVA logger.
To disable it include the following line in your code.
java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(Level.OFF);
精彩评论