or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/maven-org-slf4j--slf4j-reload4j

SLF4J binding for Reload4j (Log4j 1.2.x successor) providing logging facade integration

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/org.slf4j/slf4j-reload4j@1.7.x

To install, run

npx @tessl/cli install tessl/maven-org-slf4j--slf4j-reload4j@1.7.0

index.mddocs/

SLF4J Reload4j Binding

SLF4J Reload4j Binding provides a bridge between the SLF4J (Simple Logging Facade for Java) API and the Reload4j logging framework (successor to Log4j 1.2.x). This binding allows applications using SLF4J to delegate logging operations to Reload4j as the underlying logging implementation.

Package Information

  • Package Name: org.slf4j:slf4j-reload4j
  • Package Type: maven
  • Language: Java
  • Installation: <dependency><groupId>org.slf4j</groupId><artifactId>slf4j-reload4j</artifactId><version>1.7.36</version></dependency>

Core Imports

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.slf4j.Marker;
import org.slf4j.ILoggerFactory;
import org.slf4j.spi.MDCAdapter;
import org.slf4j.spi.LocationAwareLogger;
import org.slf4j.event.LoggingEvent;

Basic Usage

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

public class Example {
    private static final Logger logger = LoggerFactory.getLogger(Example.class);
    
    public void demonstrateLogging() {
        // Basic logging at different levels
        logger.trace("Trace level message");
        logger.debug("Debug level message");
        logger.info("Info level message");
        logger.warn("Warning message");
        logger.error("Error message");
        
        // Parameterized logging (avoids string concatenation)
        String username = "alice";
        int userId = 123;
        logger.info("User {} logged in with ID {}", username, userId);
        
        // Exception logging
        try {
            // some operation
        } catch (Exception e) {
            logger.error("Operation failed for user {}", username, e);
        }
        
        // MDC (Mapped Diagnostic Context) usage
        MDC.put("requestId", "req-456");
        logger.info("Processing request");
        MDC.remove("requestId");
    }
}

Architecture

The SLF4J Reload4j Binding operates through several key components:

  • Service Provider Interface: Implements SLF4J's service provider pattern through static binder classes
  • Logger Adapter: Wraps Reload4j loggers to provide SLF4J interface compatibility
  • Factory Pattern: Manages logger instances with caching for performance
  • MDC Integration: Bridges SLF4J's MDC with Reload4j's native MDC implementation
  • Location-Aware Logging: Supports advanced logging features like caller location information

Capabilities

Logger Factory Management

Central factory for creating and managing logger instances with efficient caching.

public class StaticLoggerBinder implements LoggerFactoryBinder {
    /**
     * Returns the singleton instance of the logger binder.
     * @return StaticLoggerBinder singleton
     */
    public static final StaticLoggerBinder getSingleton();
    
    /**
     * SLF4J API version this binding was compiled against.
     */
    public static String REQUESTED_API_VERSION;
    
    /**
     * Returns the logger factory instance.
     * @return ILoggerFactory implementation
     */
    public ILoggerFactory getLoggerFactory();
    
    /**
     * Returns the class name of the logger factory.
     * @return String representation of factory class
     */
    public String getLoggerFactoryClassStr();
}

public class Reload4jLoggerFactory implements ILoggerFactory {
    /**
     * Returns a logger instance for the given name.
     * @param name Logger name (typically class name)
     * @return Logger instance
     */
    public Logger getLogger(String name);
}

Core Logging Operations

Complete logging interface supporting all standard levels with parameterized messages and exception handling.

public final class Reload4jLoggerAdapter extends MarkerIgnoringBase 
    implements LocationAwareLogger, Serializable {
    
    // Level checking methods
    public boolean isTraceEnabled();
    public boolean isDebugEnabled();
    public boolean isInfoEnabled();
    public boolean isWarnEnabled();
    public boolean isErrorEnabled();
    
    // TRACE level logging
    public void trace(String msg);
    public void trace(String format, Object arg);
    public void trace(String format, Object arg1, Object arg2);
    public void trace(String format, Object... arguments);
    public void trace(String msg, Throwable t);
    
    // DEBUG level logging
    public void debug(String msg);
    public void debug(String format, Object arg);
    public void debug(String format, Object arg1, Object arg2);
    public void debug(String format, Object... arguments);
    public void debug(String msg, Throwable t);
    
    // INFO level logging
    public void info(String msg);
    public void info(String format, Object arg);
    public void info(String format, Object arg1, Object arg2);
    public void info(String format, Object... argArray);
    public void info(String msg, Throwable t);
    
    // WARN level logging
    public void warn(String msg);
    public void warn(String format, Object arg);
    public void warn(String format, Object arg1, Object arg2);
    public void warn(String format, Object... argArray);
    public void warn(String msg, Throwable t);
    
    // ERROR level logging
    public void error(String msg);
    public void error(String format, Object arg);
    public void error(String format, Object arg1, Object arg2);
    public void error(String format, Object... argArray);
    public void error(String msg, Throwable t);
    
    // Location-aware logging
    public void log(Marker marker, String callerFQCN, int level, String msg, Object[] argArray, Throwable t);
    public void log(LoggingEvent event);
}

Mapped Diagnostic Context (MDC)

Thread-local storage for contextual information that appears in log messages.

public class StaticMDCBinder {
    /**
     * Singleton instance for MDC binding.
     */
    public static final StaticMDCBinder SINGLETON;
    
    /**
     * Returns the singleton instance.
     * @return StaticMDCBinder singleton
     */
    public static final StaticMDCBinder getSingleton();
    
    /**
     * Returns the MDC adapter instance.
     * @return MDCAdapter implementation
     */
    public MDCAdapter getMDCA();
    
    /**
     * Returns the class name of the MDC adapter.
     * @return String representation of MDC adapter class
     */
    public String getMDCAdapterClassStr();
}

public class Reload4jMDCAdapter implements MDCAdapter {
    /**
     * Clear all entries in the MDC for the current thread.
     */
    public void clear();
    
    /**
     * Get the context value for the given key.
     * @param key Context key
     * @return Context value or null if not found
     */
    public String get(String key);
    
    /**
     * Put a context value for the given key.
     * @param key Context key (cannot be null)
     * @param val Context value (cannot be null for Log4j)
     */
    public void put(String key, String val);
    
    /**
     * Remove the context value for the given key.
     * @param key Context key to remove
     */
    public void remove(String key);
    
    /**
     * Get a copy of the current thread's context map.
     * @return Map containing all context entries, or null if empty
     */
    public Map getCopyOfContextMap();
    
    /**
     * Set the current thread's context map.
     * @param contextMap Map of context entries to set
     */
    public void setContextMap(Map contextMap);
}

Marker Support

Marker factory binding for structured logging markers.

public class StaticMarkerBinder implements MarkerFactoryBinder {
    /**
     * Singleton instance for marker binding.
     */
    public static final StaticMarkerBinder SINGLETON;
    
    /**
     * Returns the singleton instance.
     * @return StaticMarkerBinder singleton
     */
    public static StaticMarkerBinder getSingleton();
    
    /**
     * Returns the marker factory instance.
     * @return IMarkerFactory implementation (BasicMarkerFactory)
     */
    public IMarkerFactory getMarkerFactory();
    
    /**
     * Returns the class name of the marker factory.
     * @return String representation of marker factory class
     */
    public String getMarkerFactoryClassStr();
}

Types

Core type definitions referenced in the API:

// From SLF4J API
interface ILoggerFactory {
    Logger getLogger(String name);
}

interface MDCAdapter {
    void clear();
    String get(String key);
    void put(String key, String val);
    void remove(String key);
    Map getCopyOfContextMap();
    void setContextMap(Map contextMap);
}

interface LoggerFactoryBinder {
    ILoggerFactory getLoggerFactory();
    String getLoggerFactoryClassStr();
}

interface MarkerFactoryBinder {
    IMarkerFactory getMarkerFactory();
    String getMarkerFactoryClassStr();
}

interface LocationAwareLogger extends Logger {
    int TRACE_INT = 0;
    int DEBUG_INT = 10;
    int INFO_INT = 20;
    int WARN_INT = 30;
    int ERROR_INT = 40;
    
    void log(Marker marker, String fqcn, int level, String message, Object[] argArray, Throwable t);
}

interface LoggingEvent {
    Level getLevel();
    Marker getMarker();
    String getLoggerName();
    String getMessage();
    String getThreadName();
    Object[] getArgumentArray();
    long getTimeStamp();
    Throwable getThrowable();
}

enum Level {
    ERROR, WARN, INFO, DEBUG, TRACE;
    
    int toInt();
    String toString();
}

// Standard Java types used
import java.util.Map;
import java.io.Serializable;

Usage Examples

Performance-Optimized Logging

// Efficient parameterized logging (recommended)
logger.debug("Processing user {} with {} items", userId, itemCount);

// Avoid string concatenation (inefficient)
// logger.debug("Processing user " + userId + " with " + itemCount + " items");

// Level checking for expensive operations
if (logger.isDebugEnabled()) {
    String expensiveDebugInfo = computeExpensiveDebugInfo();
    logger.debug("Debug info: {}", expensiveDebugInfo);
}

Exception Logging

try {
    performDatabaseOperation();
} catch (SQLException e) {
    // Log exception with context
    logger.error("Database operation failed for user {}", userId, e);
}

MDC Usage

// Set context information
MDC.put("userId", String.valueOf(userId));
MDC.put("sessionId", sessionId);

try {
    // All log messages in this thread will include MDC context
    logger.info("Starting user operation");
    performUserOperation();
    logger.info("User operation completed successfully");
} finally {
    // Clean up MDC to prevent memory leaks
    MDC.clear();
}

Dependencies

This binding requires the following dependencies:

  • org.slf4j:slf4j-api - SLF4J API interfaces
  • ch.qos.reload4j:reload4j - Reload4j logging framework implementation

OSGi Support

The binding includes OSGi metadata and functions as a fragment bundle:

  • Bundle-SymbolicName: slf4j.reload4j
  • Export-Package: org.slf4j.impl
  • Fragment-Host: slf4j.api

Configuration

This binding delegates all configuration to the underlying Reload4j framework. Configure logging behavior through standard Reload4j configuration files (log4j.properties or log4j.xml).