Update log4j.properties to include:

log4j.logger.httpclient.wire.header=WARN
log4j.logger.httpclient.wire.content=WARN

Note that if Log4j library is not installed, HttpClient (and therefore JWebUnit) will use logback. In this situation, create or edit logback.xml to include:

<configuration>
    <logger name="org.apache" level="WARN" />
    <logger name="httpclient" level="WARN" /> 
</configuration>

Setting the log level to WARN with Log4j using the package name org.apache.commons.httpclient in log4j.properties will not work as expected:

log4j.logger.org.apache.commons.httpclient=WARN

This is because the source for HttpClient (v3.1) uses the following log names:

public static Wire HEADER_WIRE = new Wire(LogFactory.getLog("httpclient.wire.header"));
public static Wire CONTENT_WIRE = new Wire(LogFactory.getLog("httpclient.wire.content"));

Note: Some of this answer might repeat things you already know (or think you know), but there is a bit of mis-information floating around on this question, so I'm going to start at the beginning and spell it all out

  • Commons HttpClient uses Commons-Logging for all its logging needs.
  • Commons-Logging is not a full logging framework, but rather, is a wrapper around several existing logging frameworks
  • That means that when you want to control the logging output, you (mostly) end up configuring a library other than Commons-Logging, but because Commons-Logging wraps around several other libraries, it's hard for us to guess which one to configure without knowing your exactly setup.
  • Commons-Logging can log to log4j, but it can also log to java.util.logging (JDK1.4 logging)
  • Commons-Logging tries to be smart and guess which logging framework you are already using, and send its logs to that.
  • If you don't already have a logging framework, and are running on a JRE that's 1.4 or above (which you really should be) then it will probably be sending its log messages to the JDK logging (java.util.logging)
  • Relying on Commons-Logging's autodiscovery mechanism is prone to error. Simply adding log4j.jar onto the classpath would cause it to switch which logging mechanism it uses, which probably isn't what you want
  • It is preferable for you to explicitly tell Commons-Logging which logging library to use
  • You can do this by creating a commons-logging.properties file as per these instructions
  • The steps you want to follow to configure the commons-httpclient logging are
    1. Decide which underlying logging framework you want to use. There are a number of choices, but probably log4j or java.util.logging are the best options for you.
    2. Set-up the commons-logging properties file to point to the correct Log implementation. e.g. to use log4j, put this into the properties file: org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger, or to use JDK logging set org.apache.commons.logging.Log=org.apache.commons.logging.impl.Jdk14Logger. These can also be set as system properties (e.g. using -D on the command line).
    3. Configure the underlying logging implementation (e.g. log4j) to ignore the messages you don't want, and output the messages you do want.

That's a lot of steps, but that's what it takes. The developers at Apache-commons tend to assume you'll already have a logging framework configured, and they can work out which one it is by auto-discovery.
If that's not true for you, then it tends to be a bit more work to get things running.


For log4j, add the following to log4j.properties (in the application's source directory):

log4j.logger.org.apache=WARN
log4j.logger.httpclient=WARN

For logback, the following logback.xml will kill the noise:

<configuration>
    <logger name="org.apache" level="WARN" />
    <logger name="httpclient" level="WARN" /> 
</configuration>

I put this into my log4j config file

log4j.logger.org.apache.http.wire=WARN

This limits the output to Warning level or above