Commons Logging

HtmlUnit uses the commons logging package from the Apache Jakarta project. Commons logging is a thin wrapper that sits on top of other logging frameworks such as LOG4J or SLF4J.

For full details on configuring commons logging, refer to the homepage.

If you don't explicitly configure commons logging to use LOG4J or another logging framework then it will use the simple logger. When using the simple logger, you can change the default logging level by setting the following system property.

System.getProperties().put("org.apache.commons.logging.simplelog.defaultlog", "trace");

Valid values for this property are "trace", "debug", "info", "warn", "error", or "fatal" (in order from least serious to most serious).

Noteworthy loggers

In HtmlUnit, each class has its own log named according to the class's fully qualified name.

HtmlUnit uses Apache HttpClient which uses "org.apache.http" to log the headers and wire content, please read more in HttpClient Logging Practices

Logging JavaScript messages

HtmlUnit uses a slightly modified version of Rhino for JavaScript processing (htmlunit-core-js). All JavaScript related problems are forwarded to the JavaScriptErrorListener configured for the WebClient. The WebClient uses by default an instance of class 'org.htmlunit.javascript.DefaultJavaScriptErrorListener'. The DefaultJavaScriptErrorListener simply logs all information using commons logging.

final WebClient webClient = new WebClient();
webClient.setJavaScriptErrorListener(myJavaScriptErrorListener);
If you only like to ignore all JavaScript problems use SilentJavaScriptErrorListener.
final WebClient webClient = new WebClient();
webClient.setJavaScriptErrorListener(new SilentJavaScriptErrorListener());

Logging HTML parsing messages

The package used to parse the HTML (htmlunit-neko ) has the ability to report the problems it encounters while parsing source. These messages may be programmatically catched or easily logged to the 'org.htmlunit.html.HTMLParserListener' log for instance by calling:

final WebClient webClient = new WebClient();
webClient.setHTMLParserListener(HTMLParserListener.LOG_REPORTER);

Logging CSS parsing messages

HtmlUnit uses a separate CSS parser package (htmlunit-cssparser). Parsing problems are reported using the CSSErrorHandler configured for the WebClient. The WebClient by default uses an instance of class 'org.htmlunit.DefaultCssErrorHandler'. The DefaultCssErrorHandler simply logs all information using commons logging.

final WebClient webClient = new WebClient();
webClient.setCssErrorHandler(myCSSErrorHandler);
If you only like to ignore all CSS parsing problems use SilentCssErrorHandler.
final WebClient webClient = new WebClient();
webClient.setCssErrorHandler(new SilentCssErrorHandler());