Bridge that routes all Java Util Logging (JUL) log records to the SLF4J API
npx @tessl/cli install tessl/maven-org-slf4j--jul-to-slf4j@2.0.0JUL to SLF4J Bridge provides a handler that routes all Java Util Logging (JUL) log records to the SLF4J API. This bridge enables legacy applications using JUL to integrate seamlessly with modern SLF4J-based logging frameworks by installing a single handler on the root logger.
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>2.0.17</version>
</dependency>For Java 9+ modular applications with explicit module-info.java:
module your.app {
requires jul.to.slf4j;
// your other requirements
}For non-modular applications on the module path, the Automatic Module Name is jul_to_slf4j:
module your.app {
requires jul_to_slf4j; // Note: underscores, not dots
// your other requirements
}import org.slf4j.bridge.SLF4JBridgeHandler;import org.slf4j.bridge.SLF4JBridgeHandler;
import java.util.logging.Logger;
// Install the bridge to redirect all JUL logging to SLF4J
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();
// Now all JUL logging will be redirected to SLF4J
Logger julLogger = Logger.getLogger("com.example.MyClass");
julLogger.info("This message will be handled by SLF4J");
// Check if bridge is installed
if (SLF4JBridgeHandler.isInstalled()) {
System.out.println("Bridge is active");
}
// Uninstall when needed
SLF4JBridgeHandler.uninstall();The JUL to SLF4J bridge operates through a single handler class that:
Install the SLF4J bridge handler on the root logger to redirect all JUL logging.
/**
* Adds a SLF4JBridgeHandler instance to JUL's root logger
*/
public static void install();Remove previously installed SLF4J bridge handlers from the root logger.
/**
* Removes previously installed SLF4JBridgeHandler instances
* @throws SecurityException if security manager exists and caller lacks LoggingPermission("control")
*/
public static void uninstall() throws SecurityException;Check whether the SLF4J bridge handler has been installed.
/**
* Returns true if SLF4JBridgeHandler has been previously installed
* @return true if installed, false otherwise
*/
public static boolean isInstalled();Remove all handlers from the root logger, typically called before installing the bridge.
/**
* Removes/unregisters all handlers currently attached to the root logger
* @since 1.6.5
*/
public static void removeHandlersForRootLogger();Create a new SLF4JBridgeHandler instance for manual configuration.
/**
* Initialize this handler (no-op implementation)
*/
public SLF4JBridgeHandler();Process and redirect JUL log records to SLF4J loggers.
/**
* Publish a LogRecord by forwarding it to appropriate SLF4J logger
* @param record Description of the log event (null records are silently ignored)
*/
public void publish(LogRecord record);Standard handler interface methods for lifecycle management.
/**
* No-op implementation (required by Handler interface)
*/
public void close();
/**
* No-op implementation (required by Handler interface)
*/
public void flush();Internal method for resolving SLF4J loggers from JUL log records.
/**
* Return the Logger instance that will be used for logging
* @param record a LogRecord
* @return an SLF4J logger corresponding to the record parameter's logger name
*/
protected Logger getSLF4JLogger(LogRecord record);Internal method for handling location-aware logging when available.
/**
* Calls location-aware logger with proper level mapping
* @param lal LocationAwareLogger instance
* @param record LogRecord to process
*/
protected void callLocationAwareLogger(LocationAwareLogger lal, LogRecord record);
/**
* Calls plain SLF4J logger with proper level mapping
* @param slf4jLogger Logger instance
* @param record LogRecord to process
*/
protected void callPlainSLF4JLogger(Logger slf4jLogger, LogRecord record);The bridge maps JUL levels to SLF4J levels according to the following scheme:
| JUL Level | SLF4J Level |
|---|---|
| FINEST | TRACE |
| FINER | DEBUG |
| FINE | DEBUG |
| INFO | INFO |
| WARNING | WARN |
| SEVERE | ERROR |
// Standard Java imports required
import java.util.logging.Handler;
import java.util.logging.LogRecord;
import java.util.logging.Level;
import org.slf4j.Logger;
import org.slf4j.spi.LocationAwareLogger;
/**
* Bridge handler that extends java.util.logging.Handler
* to redirect JUL log records to SLF4J
*/
public class SLF4JBridgeHandler extends Handler {
// All methods listed above
}// Remove existing handlers to avoid duplication
SLF4JBridgeHandler.removeHandlersForRootLogger();
// Install the bridge
SLF4JBridgeHandler.install();
// Verify installation
if (SLF4JBridgeHandler.isInstalled()) {
// Bridge is active - all JUL logging now goes to SLF4J
}# In logging.properties
handlers = org.slf4j.bridge.SLF4JBridgeHandler// Clean shutdown
if (SLF4JBridgeHandler.isInstalled()) {
SLF4JBridgeHandler.uninstall();
}uninstall() if security manager restricts logging permissionspublish() method silently ignores null LogRecord parametersThis package requires:
The bridge is compatible with any SLF4J binding (logback, log4j2, etc.) and serves as the integration layer between JUL and SLF4J ecosystems.