|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.logging.Handler
org.slf4j.bridge.SLF4JBridgeHandler
public class SLF4JBridgeHandler
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 -> ERRORUsage:
// call only once during initialization time of your application SLF4JBridgeHandler.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
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()
Adds a SLF4JBridgeHandler instance to jul's root logger. |
void |
publish(LogRecord record)
Publish a LogRecord. |
static void |
uninstall()
Removes previously installed SLF4JBridgeHandler instances. |
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 |
---|
public SLF4JBridgeHandler()
Method Detail |
---|
public static void install()
This handler will redirect jul logging to SLF4J. However, only logs enabled in j.u.l. will be redirected. For example, if a log statement invoking a j.u.l. logger disabled that statement, by definition, will not reach any SLF4JBridgeHandler instance and cannot be redirected.
public static void uninstall() throws SecurityException
install()
.
SecurityException
- A SecurityException
is thrown, if a security manager
exists and if the caller does not have
LoggingPermission("control").public void close()
close
in class Handler
public void flush()
flush
in class Handler
protected Logger getSLF4JLogger(LogRecord record)
protected void callLocationAwareLogger(LocationAwareLogger lal, LogRecord record)
protected void callPlainSLF4JLogger(Logger slf4jLogger, LogRecord record)
public void publish(LogRecord record)
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.
publish
in class Handler
record
- Description of the log event. A null record is silently ignored
and is not published.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |