oranjestad.commons.logging
Class Log4JLoggerToJDK14Adapter

java.lang.Object
  extended by org.apache.log4j.AppenderSkeleton
      extended by oranjestad.commons.logging.Log4JLoggerToJDK14Adapter
All Implemented Interfaces:
org.apache.log4j.Appender, org.apache.log4j.spi.OptionHandler

public class Log4JLoggerToJDK14Adapter
extends org.apache.log4j.AppenderSkeleton

Class designed to handle log4j logging events by routing them to the JDK logger. This class is useful if you are combining libraries, some using log4j, others use JDK logging.

Usage

This class is intended to be added as the sole appender to the log4js Root Handler.

 Log4JLoggerToJDK14Adapter.installAdapter();
 
Can be used (or called from Spring as a factory-method) to install this adapter and begin routing messages to the JDK logger.

Implementation Notes

installAdapter() will deregister any log4j logging appenders already in place, this class is not really designed to allow continued log4j logging configuration, but instead assumes you want the events adapted to JDK logging where they can be properly configured.

Log levels are mapped as follows

Log4j LevelJDK Level
ALLFINEST
DEBUGFINER
WARNWARNING
INFOINFO
ERRORSEVERE
(any level higher than ERROR)SEVERE

Since:
1.0
Author:
Bryant Harris

Field Summary
 
Fields inherited from class org.apache.log4j.AppenderSkeleton
closed, errorHandler, headFilter, layout, name, tailFilter, threshold
 
Constructor Summary
Log4JLoggerToJDK14Adapter()
           
 
Method Summary
protected  void append(org.apache.log4j.spi.LoggingEvent logEvent)
           
 void close()
           
static Log4JLoggerToJDK14Adapter installAdapter()
          Static method for installing this adapter as the log4j's Root Logger's appender.
 boolean requiresLayout()
           
 
Methods inherited from class org.apache.log4j.AppenderSkeleton
activateOptions, addFilter, clearFilters, doAppend, finalize, getErrorHandler, getFilter, getFirstFilter, getLayout, getName, getThreshold, isAsSevereAsThreshold, setErrorHandler, setLayout, setName, setThreshold
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Log4JLoggerToJDK14Adapter

public Log4JLoggerToJDK14Adapter()
Method Detail

installAdapter

public static Log4JLoggerToJDK14Adapter installAdapter()
Static method for installing this adapter as the log4j's Root Logger's appender. This method will deregister any other appenders from the root logger.

Returns:
The appender it registered with the log4j logger.
Since:
1.0

append

protected void append(org.apache.log4j.spi.LoggingEvent logEvent)
Specified by:
append in class org.apache.log4j.AppenderSkeleton

close

public void close()
Specified by:
close in interface org.apache.log4j.Appender
Specified by:
close in class org.apache.log4j.AppenderSkeleton

requiresLayout

public boolean requiresLayout()
Specified by:
requiresLayout in interface org.apache.log4j.Appender
Specified by:
requiresLayout in class org.apache.log4j.AppenderSkeleton


Copyright © 2008. All Rights Reserved.