Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Application logging in WebSphere Application Server Community Edition

Using java.util.logging, Log4j and SLF4j

Phani Madgula (mabalaji@in.ibm.com), Software Developer, IBM
author image
Phani is currently working for WebSphere Application Server Community Edition support at India Software Labs (ISL). He has been actively involved in many projects related to migrating applications from other application servers to WebSphere Application Server Community Edition. He has 5 years experience at IBM. He worked in various product teams including WebSphere Application Server Community Edition, WebSphere Business Integration Adapters and DB2. He has experience in developing JEE applications, product support, and database administration. He is an Oracle9i certified professional.

Summary:  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.

Date:  25 Mar 2009
Level:  Intermediate PDF:  A4 and Letter (350 KB | 29 pages)Get Adobe® Reader®

Activity:  42530 views
Comments:  

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.


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.


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

1 of 9 | Next

Comments



static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=WebSphere, Open source
ArticleID=376844
TutorialTitle=Application logging in WebSphere Application Server Community Edition
publish-date=03252009
author1-email=mabalaji@in.ibm.com
author1-email-cc=