freemarker.ext.misc
Class JavaLoggingExceptionListener

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

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

Adapts FM-Classic's exception events to the java.util.logging logging methods. The Java logging package is provided with Java 1.4 or later.

Usage example:

 // Configure the logger
 Logger global = Logger.getLogger("");
 Formatter simpleFormatter = new SimpleFormatter();
 ConsoleHandler consoleHandler = new ConsoleHandler();
 consoleHandler.setFormatter(simpleFormatter);
 global.addHandler(consoleHandler);

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

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

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

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

 // Flush the handler
 consoleHandler.flush();
 

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

Constructor Summary
JavaLoggingExceptionListener()
          Creates new JavaLoggingExceptionListener
 
Method Summary
 void exceptionThrown(TemplateExceptionEvent e)
          Passes exceptions raised by FM-Classic onto the Java logging API.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JavaLoggingExceptionListener

public JavaLoggingExceptionListener()
Creates new JavaLoggingExceptionListener

Method Detail

exceptionThrown

public void exceptionThrown(TemplateExceptionEvent e)
Passes exceptions raised by FM-Classic onto the Java logging API. The log name supplied to the logger match the class and method name that caused the event to be fired.

Specified by:
exceptionThrown in interface TemplateExceptionListener