org.apache.logging.julbridge
Class JULLog4jBridge

java.lang.Object
  extended by org.apache.logging.julbridge.JULLog4jBridge

public class JULLog4jBridge
extends java.lang.Object

Helper class that creates bridge filters between java.util.logging.Loggers and an equivalent log4j Logger.

The bridge-style method calls use a Filter implementation that tries to minimise interference with the existing java.util.logging configuration, but can only bridge specific named loggers, and is not able to bridge child loggers automatically. Any Logger that is bridged that contains an existing Filter instance is delegated to when deciding if the LogRecord should continue in the java.util.logging framework, even though the bridge posts the LogRecord into log4j regardless. If there was no existing Filter defined for the bridged Logger, then the bridging Filter returns 'true' to mimic the default behaviour of not having a Filter defined.

The assimilate-style methods are much more dramatic, in that they are designed to completely take over the JUL-logging, and route all events into log4j. This mechanism resets the java.util.logging framework configuration to it's default state, which has default Level configured at INFO, and then configures the root JUL Logger with the matching Level that the provided LoggerRepository has been configured. You should, therefore, assimilate the JUL logging system after the log4j system has been properly configured. You should consider whether the default JULLevelConverter is appropriate to your needs, you may optionally provide your own conversion instance to map the 2 Level classes.

The assimilate approach is very useful for the general case where you wish to forget about JUL logging and use the flexibility of the log4j system. There is an ever so slightly higher cost in routing the event into log4j using this approach because each LogRecord received must lookup a named Logger. The bridge-style approach is slightly faster because the specifically requested logger name is looked-up on construction and re-used. Generally though, the slight performance hit is not worth the inflexibility of having to specify each and every Logger you want to bridge.

Author:
psmith
See Also:
JULLevelConverter, JULLog4jEventConverter.DEFAULT_LEVEL_CONVERTER

Constructor Summary
JULLog4jBridge()
           
 
Method Summary
static void assimilate()
           
static void assimilate(org.apache.log4j.spi.LoggerRepository repository)
           
static void assimilate(org.apache.log4j.spi.LoggerRepository repository, JULLevelConverter levelConverter)
          Completely take over the underlying java.logging sub-system.
static void bridgeJULLogger(java.lang.String JULLoggerName)
          Convenience method that gathers the default LoggerRepository and uses a default Level Converter implemenation.
static void bridgeJULLogger(java.lang.String JULLoggerName, org.apache.log4j.spi.LoggerRepository repository)
           
static void bridgeJULLogger(java.lang.String JULLoggerName, org.apache.log4j.spi.LoggerRepository repository, JULLevelConverter levelConverter)
          Creates a bridge between the named java.util.logging Logger name, and an equivalent inside the log4j LoggerRepository, using the provided level converter class.
static void repatriate()
          Reverse of assimilate(), disconnects the bridge from the java.util.logging subsystem by resetting that framework back to it's default configuration (removes all Handlers and Filters)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JULLog4jBridge

public JULLog4jBridge()
Method Detail

bridgeJULLogger

public static void bridgeJULLogger(java.lang.String JULLoggerName)
Convenience method that gathers the default LoggerRepository and uses a default Level Converter implemenation.

Parameters:
JULLoggerName -

bridgeJULLogger

public static void bridgeJULLogger(java.lang.String JULLoggerName,
                                   org.apache.log4j.spi.LoggerRepository repository)

bridgeJULLogger

public static void bridgeJULLogger(java.lang.String JULLoggerName,
                                   org.apache.log4j.spi.LoggerRepository repository,
                                   JULLevelConverter levelConverter)
Creates a bridge between the named java.util.logging Logger name, and an equivalent inside the log4j LoggerRepository, using the provided level converter class. If the JUL Logger already has a configured Filter, then it is replaced by this bridge, and a WARN level event is triggered on the JULLog4jBridge own Logger

Parameters:
JULLoggerName -
repository -

assimilate

public static void assimilate(org.apache.log4j.spi.LoggerRepository repository,
                              JULLevelConverter levelConverter)
Completely take over the underlying java.logging sub-system. Any existing java.logging configuration is reset, and a top level Handler is registered that gathers all LogRecords and converts them into log4j LoggingEvents.


assimilate

public static void assimilate(org.apache.log4j.spi.LoggerRepository repository)

assimilate

public static void assimilate()

repatriate

public static void repatriate()
Reverse of assimilate(), disconnects the bridge from the java.util.logging subsystem by resetting that framework back to it's default configuration (removes all Handlers and Filters)



Copyright 2007-2008 Apache Software Foundation. All Rights Reserved.