Thursday May 10



User Menu


AddThis Social Bookmark Button

JSF 2 Logging with Tomcat

PDF Print E-mail
Monday, 06 June 2011 10:04
AddThis Social Bookmark Button

Required Version
JSF 2 or later
Tomcat 7

How JSF 2 is structured in term of logging categories

Find below a list of logger namespaces related to JSF . FacesLogger in com.sun.faces.util package contains an enum of all application loggers

Category Description
Managed bean related logging
Faces context related logging
Logging on the rendering model
Facelets related logging
Taglib logging
Lifecycle related logging
Configuration related logging
Used by Timer class (com.sun.faces.util.Timer)
Resource logging
Application  logging

How to create an application specific logging configuration for JSF

If you want to define your own logging configuration for your web application in Tomcat you need to create a file in your src/main/resources folder for Maven users.

3 Steps to create configure :

  1. Define the handlers
  2. Configure the handlers
  3. Define category levels

Define handlers

Lets define six file handlers :

Handler Description
0error All errors
1managedbean Managed bean related logging
2config Configuration related logging
3facelets Facelets related logging
4resource Resource related logging
5lifecycle Lifecycle related logging

prefix have been added to handler names, so that multiple handlers of a single class may be instantiated. A prefix is a String which starts with a digit, and ends with '.'.
For example, 22foobar. is a valid prefix.

handlers logging definition for jsf

handlers = org.apache.juli.FileHandler, java.util.logging.ConsoleHandler, \, \, \, \, \, \

.handlers = java.util.logging.ConsoleHandle

Configure handlers

Let's define handlers specific configuration for the five file handlers we have defined.As recommended by Tomcat documentation we are using Juli file handler.  We will store each categories in a separate file located in the logs folder of Tomcat in a sub folder called Ubiteck according to the path ${catalina.base}/logs/ubiteck.

file handlers configuration for JSF 2 = FINEST = ${catalina.base}/logs/ubiteck = 00_error. com.ubiteck.jsf.util.WebAppCustomFormatter = FINEST = ${catalina.base}/logs/ubiteck = 01_managedbean. com.ubiteck.jsf.util.WebAppCustomFormatter = FINEST = ${catalina.base}/logs/ubiteck = 02_Config. com.ubiteck.jsf.util.WebAppCustomFormatter = FINEST = ${catalina.base}/logs/ubiteck = 03_Facelets. com.ubiteck.jsf.util.WebAppCustomFormatter = FINEST = ${catalina.base}/logs/ubiteck = 04_Resource. com.ubiteck.jsf.util.WebAppCustomFormatter = FINEST = ${catalina.base}/logs/ubiteck = 05_Lifecycle. com.ubiteck.jsf.util.WebAppCustomFormatter

Define category levels

Let's define what we do we want to see and at which level.

file handlers configuration for JSF 2

javax.enterprise.resource.webcontainer.jsf.handlers =

com.ubiteck.handlers =

# Catalina listener start error logging

org.apache.catalina.core.handlers =

org.apache.catalina.handlers =

# Managed Bean
javax.enterprise.resource.webcontainer.jsf.managedbean.handlers =

# Config
javax.enterprise.resource.webcontainer.jsf.config.handlers =

# Facelets
javax.enterprise.resource.webcontainer.jsf.facelets.handlers =

# Resource
javax.enterprise.resource.webcontainer.jsf.resource.handlers =

# Lifecycle
javax.enterprise.resource.webcontainer.jsf.lifecycle.handlers =
logger and handler level priority

Both the logger and its handlers have Log Levels The order of filtering is Logger then Handlers. That means it checks to see if the log message passes the loggers filter first, then sends the message on to the individual handlers for filtering.


You can now restart your application. The fives logging file and the folder containing the files will be created at start time. You are ready to debug the most complex issues you will face using JSF 2 and Tomcat.

Logging Levels

The log levels define the severity of a message. The class Level is used to define which messages should be written to the log.

Log Levels in descending order are:

  • SEVERE (highest)
  • INFO
  • FINE

In addition to that you have also the levels OFF and ALL to turn the logging of or to log everything.

For example the following will set the logger to level info which means all messages with severe, warning and info will be logged.


Logging Handlers

Each logger can have access to several handler. The handler receives the log message from the logger and exports it to a certain target A handler can be turn off with setLevel(Level.OFF) and turned on with setLevel(...)

You have several standard handler provided by J2SE :




A simple handler for writing formatted records to an OutputStream.


A simple handler for writing formatted records to System.err


A handler that writes formatted log records either to a single file, or to a set of rotating log files.


A handler that writes formatted log records to remote TCP ports.


A handler that buffers log records in memory. 

Log Levels INFO and higher will be automatically written to the console.


Each handlers output can be configured with a formatter

Available formatter

    • SimpleFormatter Generate all messages as text
    • XMLFormatter Generates XML output for the log messages

You can also build your own formatter.

Tomcat Juli

Although all JDKs ship with logging functionality provided by java.util.logging , this default implementation is not designed for container-based environments.  To get around this limitation, Tomcat replaces the default LogManager with JULI, a modified implementation with a number of additional features for handling containers.
The most notable of JULI's extended functionalities is the ability to set property files on a per-classloader basis.  This feature makes redeployment of web applications significantly less labor-intensive.

Java logging related articles

Tags: related , logging , tomcat , file , define , handler , handlers , levels


0 #1 FMT 2011-09-09 14:12
I tried to configure my as you described.

But I can't see any new log file created in the logs folder of tomcat...

I tried adding your configuration to the in the src/resources of my project and appending it to the conf/ in the tomcat installation... I tried with tomcat6 and tomcat7 with no luck.

The jsf-api and jsf-impl jars are in the lib folder of my tomcats installation for compatibility with WebSphere.

Any idea ?
Thanks in advance,

Add comment

Security code