JSF 2 Logging with Tomcat
|
|
|
| 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 |
|---|---|
javax.enterprise.resource.webcontainer.jsf.managedbean |
Managed bean related logging |
javax.enterprise.resource.webcontainer.jsf.context |
Faces context related logging |
javax.enterprise.resource.webcontainer.jsf.renderkit |
Logging on the rendering model |
javax.enterprise.resource.webcontainer.jsf.facelets |
Facelets related logging |
javax.enterprise.resource.webcontainer.jsf.taglib |
Taglib logging |
javax.enterprise.resource.webcontainer.jsf.lifecycle |
Lifecycle related logging |
javax.enterprise.resource.webcontainer.jsf.config |
Configuration related logging |
javax.enterprise.resource.webcontainer.jsf.timing |
Used by Timer class (com.sun.faces.util.Timer) |
javax.enterprise.resource.webcontainer.jsf.resource |
Resource logging |
javax.enterprise.resource.webcontainer.jsf.application |
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 logging.properties file in your src/main/resources folder for Maven users.
3 Steps to create configure :
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.
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.
Define category levels
Let's define what we do we want to see and at which level.
|
|
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)
- WARNING
- INFO
- CONFIG
- FINE
- FINER
- FINEST
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.
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 :
|
Handler |
Description |
|---|---|
|
StreamHandler |
A simple handler for writing formatted records to an OutputStream. |
|
ConsoleHandler |
A simple handler for writing formatted records to System.err |
|
FileHandler |
A handler that writes formatted log records either to a single file, or to a set of rotating log files. |
|
SocketHandler |
A handler that writes formatted log records to remote TCP ports. |
|
MemoryHandler |
A handler that buffers log records in memory. |
Log Levels INFO and higher will be automatically written to the console.
Formatter
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.
Comments
I tried to configure my logging.properties 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 logging.properties in the src/resources of my project and appending it to the conf/logging.properties 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,
Fmt
RSS feed for comments to this post