SLF4J logging provider that integrates with reload4j logging framework, replacing legacy log4j 1.2 support
npx @tessl/cli install tessl/maven-org-slf4j--slf4j-log4j12@2.0.0A SLF4J logging provider that integrates the Simple Logging Facade for Java (SLF4J) with the reload4j logging framework. This provider enables applications using SLF4J to output logs through reload4j, providing a bridge from the legacy log4j 1.2 dependency to the actively maintained reload4j fork.
<dependency><groupId>org.slf4j</groupId><artifactId>slf4j-log4j12</artifactId><version>2.0.17</version></dependency><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-reload4j</artifactId><version>2.0.17</version></dependency>// Standard SLF4J imports - no direct imports of slf4j-reload4j classes needed
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
public class ExampleApp {
private static final Logger logger = LoggerFactory.getLogger(ExampleApp.class);
public void processUser(String userId, String action) {
// Add context information to MDC
MDC.put("userId", userId);
MDC.put("action", action);
try {
logger.info("Processing user action");
// Business logic here
if (action.equals("login")) {
logger.debug("User login successful");
} else if (action.equals("logout")) {
logger.info("User logged out");
}
} catch (Exception e) {
logger.error("Error processing user action", e);
} finally {
// Clean up MDC context
MDC.clear();
}
}
}The SLF4J Reload4j Provider follows the SLF4J service provider pattern:
Reload4jServiceProvider implements SLF4JServiceProvider and is auto-discovered via Java ServiceLoaderReload4jLoggerFactory creates and caches logger instances, delegating to reload4j's LogManagerReload4jLoggerAdapter wraps reload4j Logger instances and implements SLF4J Logger interfaceReload4jMDCAdapter bridges SLF4J MDC operations to reload4j's MDC implementationThe provider automatically initializes when SLF4J is used, requiring no manual configuration beyond adding the dependency.
Core SLF4J service provider that enables automatic discovery and initialization of the reload4j logging backend.
/**
* Main SLF4J service provider for reload4j integration
*/
public class Reload4jServiceProvider implements SLF4JServiceProvider {
/** SLF4J API version compatibility marker */
public static String REQUESTED_API_VERSION = "2.0.99";
/** Default constructor that initializes marker factory and MDC adapter */
public Reload4jServiceProvider();
/** Initialize the logger factory */
public void initialize();
/** Get the logger factory instance */
public ILoggerFactory getLoggerFactory();
/** Get the marker factory instance */
public IMarkerFactory getMarkerFactory();
/** Get the MDC adapter instance */
public MDCAdapter getMDCAdapter();
/** Get the requested API version */
public String getRequestedApiVersion();
}Factory implementation that creates and manages logger instances, delegating to reload4j's LogManager.
/**
* Logger factory that creates Reload4jLoggerAdapter instances
*/
public class Reload4jLoggerFactory implements ILoggerFactory {
/** Default constructor that initializes logger cache and reload4j */
public Reload4jLoggerFactory();
/**
* Get or create a logger for the specified name
* @param name Logger name (class name or custom identifier)
* @return Logger instance for the given name
*/
public Logger getLogger(String name);
}SLF4J Logger implementation that wraps reload4j Logger instances and provides full SLF4J API compatibility.
/**
* SLF4J Logger implementation that delegates to reload4j Logger
*/
public final class Reload4jLoggerAdapter extends LegacyAbstractLogger
implements LocationAwareLogger, LoggingEventAware, Serializable {
/** Check if TRACE level is enabled */
public boolean isTraceEnabled();
/** Check if DEBUG level is enabled */
public boolean isDebugEnabled();
/** Check if INFO level is enabled */
public boolean isInfoEnabled();
/** Check if WARN level is enabled */
public boolean isWarnEnabled();
/** Check if ERROR level is enabled */
public boolean isErrorEnabled();
/**
* Location-aware logging method
* @param marker Optional marker for categorization
* @param callerFQCN Fully qualified class name of the caller
* @param level Logging level as integer
* @param msg Message to log
* @param arguments Message formatting arguments
* @param t Optional throwable for exception logging
*/
public void log(Marker marker, String callerFQCN, int level,
String msg, Object[] arguments, Throwable t);
/**
* Fluent API logging method for LoggingEvent
* @param event LoggingEvent containing all log information
*/
public void log(LoggingEvent event);
}MDC (Mapped Diagnostic Context) adapter that bridges SLF4J MDC operations to reload4j's MDC implementation.
/**
* MDC adapter that delegates to reload4j MDC implementation
*/
public class Reload4jMDCAdapter implements MDCAdapter {
/** Clear all MDC values for current thread */
public void clear();
/**
* Get MDC value for specified key
* @param key The key to retrieve
* @return String value or null if not found
*/
public String get(String key);
/**
* Put key-value pair in MDC for current thread
* @param key The key (cannot be null)
* @param val The value (cannot be null for log4j compatibility)
* @throws IllegalArgumentException if key or val is null
*/
public void put(String key, String val);
/**
* Remove key from MDC for current thread
* @param key The key to remove
*/
public void remove(String key);
/**
* Get copy of current MDC context map
* @return Map copy of current context, or null if no context
*/
public Map getCopyOfContextMap();
/**
* Set MDC context map for current thread
* @param contextMap Context map to set (null clears context)
*/
public void setContextMap(Map<String, String> contextMap);
/**
* Push value to deque by key (SLF4J 2.0 feature)
* @param key The key for the deque
* @param value The value to push
*/
public void pushByKey(String key, String value);
/**
* Pop value from deque by key (SLF4J 2.0 feature)
* @param key The key for the deque
* @return The popped value or null if deque is empty
*/
public String popByKey(String key);
/**
* Get copy of deque by key (SLF4J 2.0 feature)
* @param key The key for the deque
* @return Copy of the deque or null if not found
*/
public Deque<String> getCopyOfDequeByKey(String key);
/**
* Clear deque by key (SLF4J 2.0 feature)
* @param key The key for the deque to clear
*/
public void clearDequeByKey(String key);
}The provider is automatically discovered by SLF4J through the Java ServiceLoader mechanism:
Configuration File: META-INF/services/org.slf4j.spi.SLF4JServiceProvider
Content: org.slf4j.reload4j.Reload4jServiceProvider
No manual configuration is required - simply adding the dependency enables reload4j logging.
Logger, LoggerFactory, MDC, etc.)As of version 2.0.17, the slf4j-log4j12 artifact has been relocated to slf4j-reload4j. When you depend on org.slf4j:slf4j-log4j12:2.0.17, Maven automatically resolves it to org.slf4j:slf4j-reload4j:2.0.17. This provides backward compatibility while transitioning to the actively maintained reload4j library.
To use the provider directly without relocation, depend on:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-reload4j</artifactId>
<version>2.0.17</version>
</dependency>