Package org.slf4j.bridge
Class SLF4JBridgeHandler
java.lang.Object
java.util.logging.Handler
org.slf4j.bridge.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
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).
- Since:
- 1.5.1
- Author:
- Christian Stein, Joern Huxhorn, Ceki Gülcü, Darryl Smith, James R. Perkins
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcallLocationAwareLogger(LocationAwareLogger lal, LogRecord record) protected voidcallPlainSLF4JLogger(Logger slf4jLogger, LogRecord record) voidclose()No-op implementation.voidflush()No-op implementation.protected LoggergetSLF4JLogger(LogRecord record) Return the Logger instance that will be used for logging.static voidinstall()Adds a SLF4JBridgeHandler instance to jul's root logger.static booleanReturns true if SLF4JBridgeHandler has been previously installed, returns false otherwise.voidPublish a LogRecord.static voidInvoking this method removes/unregisters/detaches all handlers currently attached to the root loggerstatic voidRemoves previously installed SLF4JBridgeHandler instances.Methods inherited from class java.util.logging.Handler
getEncoding, getErrorManager, getFilter, getFormatter, getLevel, isLoggable, reportError, setEncoding, setErrorManager, setFilter, setFormatter, setLevel
-
Constructor Details
-
SLF4JBridgeHandler
public SLF4JBridgeHandler()Initialize this handler.
-
-
Method Details
-
install
public static void install()Adds a SLF4JBridgeHandler instance to jul's root logger. 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. -
uninstall
Removes previously installed SLF4JBridgeHandler instances. See alsoinstall().- Throws:
SecurityException- ASecurityExceptionis thrown, if a security manager exists and if the caller does not have LoggingPermission("control").
-
isInstalled
Returns true if SLF4JBridgeHandler has been previously installed, returns false otherwise.- Returns:
- Throws:
SecurityException
-
removeHandlersForRootLogger
public static void removeHandlersForRootLogger()Invoking this method removes/unregisters/detaches all handlers currently attached to the root logger- Since:
- 1.6.5
-
close
public void close()No-op implementation. -
flush
public void flush()No-op implementation. -
getSLF4JLogger
Return the Logger instance that will be used for logging. -
callLocationAwareLogger
-
callPlainSLF4JLogger
-
publish
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.
-