O'Reilly logo

JBoss at Work: A Practical Guide by Scott Davis, Tom Marrs

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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:

Debugging

Developers generate log messages to debug their programs.

Reviewing

System personnel examine log messages to check for problems.

Auditing

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. InitServlet.java
...

import org.apache.commons.logging.*;

...

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

    private ServletContext servletContext;

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

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required