Using logging within an EJB

Logging is a useful technique for recording exceptions and significant events which occur during the execution of an application. While there are many different logging APIs available, we will focus on those classes found in the java.util.logging package. If you are interested you may find alternate logging technologies such as log4j ( or the Simple Logging Facade for Java (SLF4J) ( to be useful.

Getting ready

The process of creating using a logger involves:

  1. Importing the java.util.logging package
  2. Using the Logger class' static method getLogger to obtain an instance of a logger
  3. Using methods of the Logger to record application data
  4. Optionally, various filters, handlers, ...

Get EJB 3.1 Cookbook now with O’Reilly online learning.

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