public class SLF4JBridgeHandler extends Handler
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
Please note that translating a java.util.logging event into SLF4J incurs the
cost of constructing LogRecord
instance regardless of whether the
SLF4J logger is disabled for the given level. Consequently, j.u.l. to
SLF4J translation can seriously impact on the cost of disabled logging
statements (60 fold increase) and a measurable impact on enabled log
statements (20% overall increase).
Constructor and Description |
---|
SLF4JBridgeHandler()
Initialize this handler.
|
Modifier and Type | Method and Description |
---|---|
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.
|
static boolean |
isInstalled()
Returns true if SLF4JBridgeHandler has been previously installed, returns false otherwise.
|
void |
publish(LogRecord record)
Publish a LogRecord.
|
static void |
removeHandlersForRootLogger()
Invoking this method removes/unregisters/detaches all handlers currently attached to the root logger
|
static void |
uninstall()
Removes previously installed SLF4JBridgeHandler instances.
|
getEncoding, getErrorManager, getFilter, getFormatter, getLevel, isLoggable, reportError, setEncoding, setErrorManager, setFilter, setFormatter, setLevel
public static void install()
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 static boolean isInstalled() throws SecurityException
SecurityException
public static void removeHandlersForRootLogger()
protected Logger getSLF4JLogger(LogRecord record)
protected void callLocationAwareLogger(LocationAwareLogger lal, LogRecord record)
public void publish(LogRecord record)
Copyright © 2017 JBoss by Red Hat. All rights reserved.