Introduction
Application logging provides ways to capture various events happening in the execution of an application. It gathers information in detail about what the application is doing when the application performs various tasks. This information is useful for debugging, troubleshooting and even auditing. WebSphere® Application Server Community Edition (hereafter called Community Edition) ships with various libraries that help application developers configure logging services. These libraries are:
- Log4j
- SLF4j
- java.util.logging
The java.util.logging package is a Java API for logging that is available in all standard Java development kits. This tutorial explains with samples how to use these APIs in applications deployed on Community Edition.
You configure java.util.logging per JVM instance. Once configured, it is available to all the applications running on that server. This tutorial explains how to use java.util.logging in the applications running on Community Edition.
The most commonly used API for logging is Log4j from the Apache Software Foundation. Community Edition ships with Log4j libraries that are used by the server modules at runtime. Applications can also use these libraries; they can either log messages to the same destination as the server logs at the runtime, or they can configure their own logging destinations and formats as desired. This tutorial demonstrates different ways to configure logging using Log4j in Community Edition.
The Simple Logging Facade for Java (or
SLF4j) is yet another
logging API that applications can use as a logging service. SLF4j does
not invent another logging framework but allows applications use a
standard API and plug in the actual logging implementation at
deployment time, such as,
NOP, Simple, log4j version 1.2, JDK 1.4 logging, JCL
and logback. Community Edition also ships
with SLF4j libraries. This tutorial demonstrates how to use SLF4j over
log4j in the applications targeted to run on Community Edition.
Community Edition v2.1 is a lightweight application server that is based on Apache Geronimo v2.1. Community Edition also includes many other defect fixes, and receives world-class support from IBM. You can download the binary images of the server for no charge. It is a fully certified server for Java EE 5.
This tutorial shows how to use java.util.logging, Log4j and SLF4j APIs
in applications targeted to run on Community Edition. It contains the
following sections:
- Setting up the environment
- Configuring java.util.logging in Community Edition
- Community Edition nuances and getting the most from Log4j
- Using SLF4j in the Community Edition
In each section, we briefly describe the corresponding logging API and
explain various ways to configure and use the API to obtain desired
logging behavior. We use the EMPDemo sample
to demonstrate how to use the three logging APIs. The
EMPDemo sample can be downloaded from the
developerWorks
site.
You should be fairly skilled in Java programming. Understanding Java EE 5 concepts and database concepts will help you with the context of the tutorial. If you have experience running a HelloWorld sample on Community Edition and writing Community Edition deployment plans, you are the perfect candidate to get most out of the tutorial.
To develop, deploy and run the application, the following environment is required:
- IBM Java SDK v1.5.0 SR8 or above
- Community Edition v2.1.0.1 or above
We use the Apache Derby database shipped with Community Edition
to deploy and run the EMPDemo application.
The EMPDemo application connects to
EMPLOYEE_DB in
the embedded Derby database and retrieves information from the
EMPLOYEE table. We then show the retrieved
information to the user on the browser. We demonstrate using logging
APIs to log messages when the application performs various database
operations.
Duration
2 hours





