or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/maven-org-slf4j--jul-to-slf4j

Bridge that routes all Java Util Logging (JUL) log records to the SLF4J API

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/org.slf4j/jul-to-slf4j@2.0.x

To install, run

npx @tessl/cli install tessl/maven-org-slf4j--jul-to-slf4j@2.0.0

index.mddocs/

JUL to SLF4J Bridge

JUL 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.

Package Information

  • Package Name: jul-to-slf4j
  • Package Type: maven
  • Language: Java
  • Group ID: org.slf4j
  • Artifact ID: jul-to-slf4j
  • Module Name: jul.to.slf4j (explicit module) / jul_to_slf4j (automatic module)
  • Installation:
    <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
}

Core Imports

import org.slf4j.bridge.SLF4JBridgeHandler;

Basic Usage

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();

Architecture

The JUL to SLF4J bridge operates through a single handler class that:

  • Handler Installation: Installs on JUL's root logger as the sole handler
  • Level Mapping: Maps JUL levels to equivalent SLF4J levels (FINEST→TRACE, FINER→DEBUG, etc.)
  • Location Awareness: Supports location-aware logging when available for better debugging
  • Resource Bundle Support: Handles JUL message formatting with resource bundles
  • Thread Safety: Safe for concurrent use in multi-threaded applications

Capabilities

Bridge Installation

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();

Bridge Removal

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;

Installation Status

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();

Root Logger Cleanup

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();

Handler Instance Creation

Create a new SLF4JBridgeHandler instance for manual configuration.

/**
 * Initialize this handler (no-op implementation)
 */
public SLF4JBridgeHandler();

Log Record Processing

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);

Handler Management

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();

Logger Resolution

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);

Location-Aware Logging

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);

Level Mapping

The bridge maps JUL levels to SLF4J levels according to the following scheme:

JUL LevelSLF4J Level
FINESTTRACE
FINERDEBUG
FINEDEBUG
INFOINFO
WARNINGWARN
SEVEREERROR

Types

// 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
}

Usage Patterns

Standard Installation Pattern

// 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
}

Configuration-Based Installation

# In logging.properties
handlers = org.slf4j.bridge.SLF4JBridgeHandler

Programmatic Cleanup

// Clean shutdown
if (SLF4JBridgeHandler.isInstalled()) {
    SLF4JBridgeHandler.uninstall();
}

Error Handling

  • SecurityException: May be thrown by uninstall() if security manager restricts logging permissions
  • Null Records: publish() method silently ignores null LogRecord parameters
  • Missing Loggers: Uses fallback logger name "unknown.jul.logger" for records without names

Dependencies

This package requires:

  • slf4j-api: Core SLF4J API for logger instances and interfaces
  • Java Util Logging: Standard Java logging framework (java.util.logging)

The bridge is compatible with any SLF4J binding (logback, log4j2, etc.) and serves as the integration layer between JUL and SLF4J ecosystems.