org.slf4j.bridge
Class SLF4JBridgeHandler

java.lang.Object
  extended by java.util.logging.Handler
      extended by org.slf4j.bridge.SLF4JBridgeHandler

public class SLF4JBridgeHandler
extends Handler

Bridge/route all JUL log records to the SLF4J API.

Essentially, the idea is to install on the root logger an instance of SLF4JBridgeHandler as the sole JUL handler in the system. Subsequently, the SLF4JBridgeHandler instance will redirect all JUL log records are redirected to the SLF4J API based on the following mapping of levels:

 FINEST  -> TRACE
 FINER   -> DEBUG
 FINE    -> DEBUG
 INFO    -> INFO
 WARNING -> WARN
 SEVER   -> ERROR
 
Usage:
   // call only once during initialization time of your application
   SLF4JHandler.install();
   
   // usual pattern: get a Logger and then log a message
   java.util.logging.Logger julLogger = java.util.logging.Logger.getLogger("org.wombat");
   julLogger.fine("hello world"); // this will get redirected to SLF4J
 

Since:
1.5.1
Author:
Christian Stein, Joern Huxhorn, Ceki G¨lc¨

Constructor Summary
SLF4JBridgeHandler()
          Initialize this handler.
 
Method Summary
protected  void callLocationAwareLogger(LocationAwareLogger lal, LogRecord record)
           
protected  void callPlainSLF4JLogger(Logger slf4jLogger, LogRecord record)
           
 void close()
          No-op implementation.
 void flush()
          No-op implementation.
protected  Logger getSLF4JLogger(LogRecord record)
          Return the Logger instance that will be used for logging.
static void install()
          Resets the entire JUL logging system and adds new SLF4JHandler instance to the root logger.
 void publish(LogRecord record)
          Publish a LogRecord.
static void uninstall()
          Rereads the JUL configuration.
 
Methods inherited from class java.util.logging.Handler
getEncoding, getErrorManager, getFilter, getFormatter, getLevel, isLoggable, reportError, setEncoding, setErrorManager, setFilter, setFormatter, setLevel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SLF4JBridgeHandler

public SLF4JBridgeHandler()
Initialize this handler.

Method Detail

install

public static void install()
Resets the entire JUL logging system and adds new SLF4JHandler instance to the root logger.


uninstall

public static void uninstall()
                      throws Exception
Rereads the JUL configuration.

Throws:
Exception - A SecurityException is thrown, if a security manager exists and if the caller does not have LoggingPermission("control"). IOException if there are IO problems reading the configuration.
See Also:
LogManager.readConfiguration();

close

public void close()
No-op implementation.

Specified by:
close in class Handler

flush

public void flush()
No-op implementation.

Specified by:
flush in class Handler

getSLF4JLogger

protected Logger getSLF4JLogger(LogRecord record)
Return the Logger instance that will be used for logging.


callLocationAwareLogger

protected void callLocationAwareLogger(LocationAwareLogger lal,
                                       LogRecord record)

callPlainSLF4JLogger

protected void callPlainSLF4JLogger(Logger slf4jLogger,
                                    LogRecord record)

publish

public void publish(LogRecord record)
Publish a LogRecord.

The logging request was made initially to a Logger object, which initialized the LogRecord and forwarded it here.

This handler ignores the Level attached to the LogRecord, as SLF4J cares about discarding log statements.

Specified by:
publish in class Handler
Parameters:
record - Description of the log event. A null record is silently ignored and is not published.


Copyright © 2005-2009 QOS.ch. All Rights Reserved.