Tuesday, March 10, 2009

Disable HtmlUnit logging

HtmlUnit is a pretty decent scriptable browser. I use it for developing alot of website scrapers and various bots. By default, the logging to the standard output stream is pretty verbose. A quick way to disable it programmatically is to add the following static initializer to your code:

   static {
        LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog");
    }

6 comments:

Unknown said...

didnt work for me...
what did work was:
create a new incorectness listener:
public class IncLis implements IncorrectnessListener {
@Override
public void notify(String arg0, Object arg1) {}
}
and add it to my webClient:
IncLis inclis = new IncLis();
webClient.setIncorrectnessListener(inclis);

venkatsalem said...

Thanks, It worked for me.

renaud.richardet said...

Thanks Adam!

Radu Vlad said...

Worked perfectly!

Unknown said...

webClient.setThrowExceptionOnFailingStatusCode(false);
webClient.setThrowExceptionOnScriptError(false);

Anonymous said...

+1 Worked like a charm!

Thank you! :)