Skip to main content

skip to main content

developerWorks  >  WebSphere | Open source  >

Application logging in WebSphere Application Server Community Edition

Using java.util.logging, Log4j and SLF4j

developerWorks
Page 1 of 10 Go to the next page

Document options
PDF format - Fits A4 and Letter

PDF - Fits A4 and Letter
349 KB (29 pages)

Get Adobe® Reader®

Sample code


My developerWorks needs you!

Connect to your technical community


Rate this tutorial

Help us improve this content


Level: Intermediate

Phani Madgula (mabalaji@in.ibm.com), Software Developer, IBM

25 Mar 2009

WebSphere Application Server Community Edition provides several ways to configure application logging, using java.util.logging, Log4j and SLF4j APIs. Though the steps to configure these logging services are to large extent independent of any application server, WebSphere Application Server requires certain tweaks to get your desired logging behavior. This tutorial walks you through these tweaks coupled with sample applications. WebSphere® Application Server Community Edition is freely available for download, so you can get started in just a few minutes.

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.

In this tutorial

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:

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.



Back to top


Prerequisites

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.



Back to top


System Requirements

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



Back to top



Page 1 of 10 Go to the next page