General Logging Configuration

Commons Logging

HtmlUnit uses the Commons Logging package from the Apache Commons 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 its homepage.

If you don't explicitly configure Commons Logging to use Log4j or another logging framework, it will default to SimpleLog. When using SimpleLog, 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 headers and wire content. Please read more in HttpClient Logging Practices.

Subsystem Loggers

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 defaults to using an instance of org.htmlunit.javascript.DefaultJavaScriptErrorListener, which simply logs all information using Commons Logging.

final WebClient webClient = new WebClient();
webClient.setJavaScriptErrorListener(myJavaScriptErrorListener);

If you prefer 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 HTML (htmlunit-neko) has the ability to report the problems it encounters while parsing source. These messages may be programmatically caught 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. By default, the WebClient uses an instance of class org.htmlunit.DefaultCssErrorHandler, which simply logs all information using Commons Logging.

final WebClient webClient = new WebClient();
webClient.setCssErrorHandler(myCSSErrorHandler);

If you prefer to ignore all CSS parsing problems, use SilentCssErrorHandler:

final WebClient webClient = new WebClient();
webClient.setCssErrorHandler(new SilentCssErrorHandler());