Appendix B. Logging and JBoss

Most J2EE applications use some form of logging or tracing API that stores messages to a persistent medium (such as DBMS or file). Logging provides the following benefits:


Developers generate log messages to debug their programs.


System personnel examine log messages to check for problems.


Security personnel can review log messages to see what actions a user performed in the system.

This chapter covers two of the most common logging APIs and how to use them with JBoss:

  • Jakarta Commons Logging (JCL) API

  • Apache Log4J

Jakarta Commons Logging (JCL) API

The Jakarta Commons Logging (JCL) package from the Apache Jakarta project provides a standard interface to the various logging libraries, hiding the details of the logging implementation from an application. Many logging APIs are available, and at some point an application may need to change to another logging technology. The main benefit of the JCL is that it enables developers to switch between logging implementations without impacting their code.

Using the Apache JCL

Example B-1 is an example from the JAW Motors InitServlet that uses the JCL to print out a log message.

Example B-1.

import org.apache.commons.logging.*;


public class InitServlet extends GenericServlet {
    private Log log = LogFactory.getLog(InitServlet.class);

    private ServletContext servletContext;

    public void init() {
        ..."Testing Logging Setup ...");

The call to LogFactory.getLog() creates ...

Get JBoss at Work: A Practical Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.