freemarker.ext.misc
Class Log4jExceptionListener

java.lang.Object
  extended by freemarker.ext.misc.Log4jExceptionListener
All Implemented Interfaces:
TemplateExceptionListener, java.util.EventListener

public final class Log4jExceptionListener
extends java.lang.Object
implements TemplateExceptionListener

Adapts FM-Classic's exception events to Log4j's logging methods. This code is known to work with Log4j version 1.1.3, but should be compatible with earlier versions as well.

Log4j can be found at the Jakarta Apache web site.

Usage example:

 // Configure Log4j
 Category rootCategory = Category.getRoot();
 PatternLayout patternLayout = new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN);
 ConsoleAppender consoleAppender = new ConsoleAppender(patternLayout, "System.err");
 rootCategory.addAppender(consoleAppender);

 // Set up the template
 Template template = new Template(filename);

 // Set up the model
 TemplateModelRoot modelRoot = (...)

 // Set up the listener
 SimpleEventAdapter adapter = new SimpleEventAdapter( new Log4jExceptionListener() );

 // Call the template
 template.process( modelRoot, writer, adapter );
 

Version:
$Id: Log4jExceptionListener.java 1152 2013-04-15 10:34:50Z run2000 $
Author:
Nicholas Cull

Constructor Summary
Log4jExceptionListener()
          Creates new Log4jExceptionListener
 
Method Summary
 void exceptionThrown(TemplateExceptionEvent e)
          Passes exceptions raised by FreeMarker onto Log4j.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Log4jExceptionListener

public Log4jExceptionListener()
Creates new Log4jExceptionListener

Method Detail

exceptionThrown

public void exceptionThrown(TemplateExceptionEvent e)
Passes exceptions raised by FreeMarker onto Log4j. The categories supplied to Log4j match the class and method name that caused the event to be fired.

Specified by:
exceptionThrown in interface TemplateExceptionListener