Logging Practices

HttpClient utilizes the logging interface provided by the Jakarta Commons Logging package. Commons Logging provides a simple and generalized log interface to various logging packages. By using the Commons Logging configuration, HttpClient can be configured for a variety of logging behaviours.

There are two specific types of loggers used within HttpClient : the standard log used for each class and the wireLog used for wire messages. Commons Logging allows for various logging systems to do the actual output. The most basic is SimpleLog which uses stdout to write log messages. All the following examples are shown with SimpleLog to highlight the utility within HttpClient

log

The logging output can be configured on a class by class basis if desired. This is accomplished by setting a system property for each class. For example, if you wanted to see extremely detailed information on authentication routines, you could turn up the logging level for the Authenticator by setting the following property:

org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient.Authenticator=trace

The default log level for all classes can be set to a default by using the following:

org.apache.commons.logging.simplelog.defaultlog=info

wireLog

There is one log that cuts across several classes that is used for logging wire messages. Careful when turning this on as potentially a huge volume of data may be written, some of it in binary format.

org.apache.commons.logging.simplelog.log.httpclient.wire=debug

When troubleshooting a problem, it is good to turn on the log to find out what is going on, both over the wire and in httpclient. The following statements can be used to configure the logger from within your java application:

System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");

System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true");

System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire", "debug");

System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", "debug");