Introduction
Application logging provides a way to capture the various events that occur during application execution. It collects detailed information about what the application is doing when it performs various tasks. This information is useful for debugging, troubleshooting, and even auditing. The websphere®application Server Community Edition (hereinafter called Community Edition) provides a variety of libraries that help application developers configure the logging service. These libraries are:
Log4j
Slf4j
Java.util.logging
The java.util.logging package is a log logging Java API available for all standard Java development kits. This tutorial provides an example of how to use these APIs in applications deployed in Community Edition.
You will configure java.util.logging by the JVM instance. After you configure it, you can use it for all applications running on that server. This tutorial describes how to use java.util.logging in an application running on Community Edition.
The most commonly used logging APIs are the log4j in Apache Software Foundation. The log4j library provided by Community Edition can be used by the server module at run time. Applications can also use these libraries, which can log messages to the same server as the server log at run time, or configure their own logging destinations and formats as needed. This tutorial demonstrates different ways to use log4j configuration logging in Community Edition.
Simple Logging façade for Java (or SLF4J) is another logging API available for applications to use as logging services. SLF4J does not create another logging framework, but allows applications to use standard APIs and inserts actual logging implementations at deployment time, such as NOP, simple, log4j V1.2, JDK 1.4 logging, JCL, and Logback. Community Edition also provides a slf4j library. This tutorial will show you how to use slf4j on log4j in an application running in Community Edition.
Community Edition v2.1 is a lightweight application server based on the Apache Geronimo v2.1. Community Edition also contains a number of other bug fixes and has world-class support from IBM. You can download the server's binary image for free. It is a fully authenticated server for Java EE 5.
This tutorial
This tutorial describes how to use the Java.util.logging, log4j, and SLF4J APIs in applications designed to run on Community Edition. These include the following sections:
Setting up the environment
Configuring Java.util.logging in Community Edition
Uniqueness of Community Edition and its full utilization log4j
Using SLF4J in Community Edition
In each section, we will briefly describe the appropriate logging APIs and describe the various ways to configure and use APIs to get the required logging behavior. We will use the Empdemo sample to demonstrate how to use these three logging APIs. The Empdemo sample can be downloaded from the DeveloperWorks Web site.
Prerequisite
You should have quite a lot of Java programming skills. Understanding the Java EE 5 concepts and database concepts will help you clarify the context of this tutorial. If you have the experience of running the HelloWorld sample on Community Edition and have written Community Edition deployment plan, it would be great to take advantage of this tutorial.