2010-04-14 - Jakarta Taglibs has been retired.

For more information, please explore the Attic.

Jakarta Project: Log Tag library

Version: 1.0

Table of Contents

Overview

The Log library allows you to embed logging calls in your JSP which can be output to a variety of destinations thanks to the power of the log4j project.

Initialising log4j

By default these log tags do not explicitly initialise log4j, you are free to do that however you wish. A common approach is to create a log4j servlet and for it to initialise log4j using some configuration file or options specified in your web.xml

My own personal preference is just to put a log4j.properties file in the WEB-INF/classes directory and for that to have your log4j configuration. Then without any special servlets or initialisation code log4j will correctly initialise itself. This approach also avoids a single web app accidentally initialising log4j several times (e.g. via 2 different servlets).

If you have any further questions regarding the configuration of log4j please visit the log4j site or a log4j specific mailing list.

Requirements

Configuration

Follow these steps to configure your web application with this tag library:

To use the tags from this library in your JSP pages, add the following directive at the top of each page:

<%@ taglib uri="http://jakarta.apache.org/taglibs/log-1.0" prefix="log" %>

where "log" is the tag name prefix you wish to use for tags from this library. You can change this value to any prefix you like.

Tag Summary

Loggin Tags
debugDisplays a debug-level message
infoDisplays a info-level message
warnDisplays a warn-level message
errorDisplays a error-level message
fatalDisplays a fatal message, usually as the application is about to terminate
dumpDisplays all vars in the specified scope
 

Tag Reference

debug Availability: 

Displays a debug-level message

Tag Body    
Restrictions

AttributesNameRequired Runtime Expression Evaluation Availability
 category  No   Yes  
 

The log4j category name used to log this message to. If this is not specified then the default log4j category is used.

 message  No   Yes  
 

The message to log. If this is not specified then the body of the tag is used instead.

VariablesNone
 
 


<log:debug message="this is a message"/>

<log:debug category="foo.bar" message="this is a message"/>

<log:debug category="foo.bar">
  this is a message
</log:debug>

info Availability: 

Displays a info-level message

Tag Body    
Restrictions

AttributesNameRequired Runtime Expression Evaluation Availability
 category  No   Yes  
 

The log4j category name used to log this message to. If this is not specified then the default log4j category is used.

 message  No   Yes  
 

The message to log. If this is not specified then the body of the tag is used instead.

VariablesNone
 
 


<log:info message="this is a message"/>

<log:info category="foo.bar" message="this is a message"/>

<log:info category="foo.bar">
  this is a message
</log:description>

warn Availability: 

Displays a warn-level message

Tag Body    
Restrictions

AttributesNameRequired Runtime Expression Evaluation Availability
 category  No   Yes  
 

The log4j category name used to log this message to. If this is not specified then the default log4j category is used.

 message  No   Yes  
 

The message to log. If this is not specified then the body of the tag is used instead.

VariablesNone
 
 


<log:warn message="this is a message"/>

<log:warn category="foo.bar" message="this is a message"/>

<log:warn category="foo.bar">
  this is a message
</log:warn>

error Availability: 

Displays a error-level message

Tag Body    
Restrictions

AttributesNameRequired Runtime Expression Evaluation Availability
 category  No   Yes  
 

The log4j category name used to log this message to. If this is not specified then the default log4j category is used.

 message  No   Yes  
 

The message to log. If this is not specified then the body of the tag is used instead.

VariablesNone
 
 


<log:error message="this is a message"/>

<log:error category="foo.bar" message="this is a message"/>

<log:error category="foo.bar">
  this is a message
</log:error>

fatal Availability: 

Displays a fatal message, usually as the application is about to terminate

Tag Body    
Restrictions

AttributesNameRequired Runtime Expression Evaluation Availability
 category  No   Yes  
 

The log4j category name used to log this message to. If this is not specified then the default log4j category is used.

 message  No   Yes  
 

The message to log. If this is not specified then the body of the tag is used instead.

VariablesNone
 
 


<log:fatal message="oh dear I think I'm about to terminate"/>

<log:fatal category="foo.bar" message="oh dear I think I'm about to terminate"/>

<log:fatal category="foo.bar">
  oh dear I think I'm about to terminate
</log:fatal>

dump Availability: 

Displays all vars in the specified scope

Tag Body    
Restrictions

AttributesNameRequired Runtime Expression Evaluation Availability
 scope  Yes   Yes  
 
VariablesNone
 
 


<log:dump scope="page"/>
<log:dump scope="request"/>
<log:dump scope="session"/>
<log:dump scope="application"/>

Examples

See the example application log-examples.war for examples of the usage of the tags from this custom tag library.

Java Docs

Java programmers can view the java class documentation for this tag library as javadocs.

Revision History

Review the complete revision history of this tag library.