User guide
Logging AWS SDK for Java Calls
The AWS SDK for Java is instrumented with Apache Commons Logging, which is an abstraction layer
that enables the use of any one of a number of logging systems at runtime. Supported logging systems
include the Java Logging Framework and Apache Log4j, among others. This topic explains how to use
Log4j.You can learn more about Log4j on the Log4j page at the Apache website.You can use the SDK's
logging functionality without making any changes to your application code.
In order to use Log4j with the SDK, you need to download the Log4j jar from the Apache website.The
jar is not included in the SDK. Copy the jar file to a location that is on your classpath.
Log4j uses a configuration file, log4j.properties. Example configuration files are shown below. Copy this
configuration file to a directory on your classpath. The Log4j jar and the log4j.properties file do not have
to be in the same directory.
The log4j.properties configuration file specifies properties such as logging level, where logging output is
sent (such as to a file or to the console), and the format of the output.The logging level is the granularity
of output that the logger generates. Log4j supports the concept of multiple logging hierarchies.The logging
level is set independently for each hierarchy. The following two logging hierarchies are available in the
SDK.
• log4j.logger.com.amazonaws
• log4j.logger.org.apache.http.wire
Setting the Classpath
Both the Log4j jar and the log4j.properties file must be located on your classpath. If you are using Apache
Ant, set the classpath in the path element in your Ant file. Here is an example path element from the Ant
file for the Amazon S3 example included with the SDK:
<path id="aws.java.sdk.classpath">
<fileset dir="../../third-party" includes="**/*.jar"/>
<fileset dir="../../lib" includes="**/*.jar"/>
<pathelement location="."/>
</path>
If you are using the Eclipse IDE, you can set the classpath by navigating to:
Project | Properties | Java Build Path
Service-Specific Errors and Warnings
We recommend that you always leave the "com.amazonaws" logger hierarchy set to "WARN" in order to
catch any important messages from the client libraries. For example, if the Amazon S3 client detects that
your application hasn't properly closed an InputStream and could be leaking resources, it will report it
through a warning message to the logs. This will also ensure that messages are logged if the client has
any problems handling requests or responses.
The following log4j.properties file sets the rootLogger to WARN, which will cause warning and error
messages from all loggers in the "com.amazonaws" hierarchy to be included. Alternatively, you can
explicitly set the com.amazonaws logger to WARN.
Version v1.0.0
15
AWS SDK for Java Developer Guide
Logging