CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-slf4j--log4j-over-slf4j

Log4j 1.x API compatibility layer that implements Apache Log4j API over SLF4J for seamless migration

Pending
Overview
Eval results
Files

configuration.mddocs/

Configuration

Configuration utilities providing Log4j 1.x API compatibility for basic and property-based configuration. All configuration classes are implemented as no-op since actual configuration is handled by the underlying SLF4J implementation (e.g., Logback).

Capabilities

Basic Configuration

Simple configuration utilities for basic logging setup. These methods maintain API compatibility but perform no actual configuration.

/**
 * Basic configuration setup (no-op implementation)
 */
public static void configure();

/**
 * Configure with a specific appender (no-op implementation)
 * @param appender Appender to configure with
 */
public static void configure(Appender appender);

/**
 * Reset logging configuration (no-op implementation)
 */
public static void resetConfiguration();

Usage Examples:

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.SimpleLayout;

// Basic configuration (no-op, but maintains API compatibility)
BasicConfigurator.configure();

// Configure with console appender (no-op)
ConsoleAppender appender = new ConsoleAppender(new SimpleLayout());
BasicConfigurator.configure(appender);

// Reset configuration (no-op)
BasicConfigurator.resetConfiguration();

// Note: Actual configuration must be done through SLF4J implementation
// For example, with Logback, use logback.xml or logback-spring.xml

Property Configuration

Property-based configuration system implementing the Configurator interface. All methods are no-op implementations.

/**
 * PropertyConfigurator implementing Configurator interface
 */
public class PropertyConfigurator implements Configurator {
    
    /**
     * Configure from Properties object (no-op)
     * @param properties Properties for configuration
     */
    public static void configure(Properties properties);
    
    /**
     * Configure from properties file (no-op)
     * @param configFilename Path to properties file
     */
    public static void configure(String configFilename);
    
    /**
     * Configure from URL (no-op)
     * @param configURL URL to properties file
     */
    public static void configure(URL configURL);
    
    /**
     * Configure and watch file for changes (no-op)
     * @param configFilename Path to properties file
     */
    public static void configureAndWatch(String configFilename);
    
    /**
     * Configure and watch file for changes with delay (no-op)
     * @param configFilename Path to properties file
     * @param delay Watch delay in milliseconds
     */
    public static void configureAndWatch(String configFilename, long delay);
    
    /**
     * Configure from Properties with logger repository (no-op)
     * @param properties Properties for configuration
     * @param hierarchy Logger repository
     */
    public void doConfigure(Properties properties, LoggerRepository hierarchy);
    
    /**
     * Configure from file with logger repository (no-op)
     * @param configFileName Path to properties file
     * @param hierarchy Logger repository
     */
    public void doConfigure(String configFileName, LoggerRepository hierarchy);
    
    /**
     * Configure from URL with logger repository (no-op)
     * @param configURL URL to properties file
     * @param hierarchy Logger repository
     */
    public void doConfigure(URL configURL, LoggerRepository hierarchy);
}

Usage Examples:

import org.apache.log4j.PropertyConfigurator;
import java.util.Properties;
import java.net.URL;

// Configure from properties file (no-op)
PropertyConfigurator.configure("log4j.properties");

// Configure from Properties object (no-op)
Properties props = new Properties();
props.setProperty("log4j.rootLogger", "INFO, console");
PropertyConfigurator.configure(props);

// Configure from URL (no-op)
URL configURL = new URL("http://example.com/log4j.properties");
PropertyConfigurator.configure(configURL);

// Configure and watch for changes (no-op)
PropertyConfigurator.configureAndWatch("log4j.properties");
PropertyConfigurator.configureAndWatch("log4j.properties", 60000); // Check every minute

// Instance-based configuration (no-op)
PropertyConfigurator configurator = new PropertyConfigurator();
configurator.doConfigure("log4j.properties", null);

XML Configuration

XML-based configuration using DOM parser. Implemented as no-op.

/**
 * XML-based configuration using DOM parser (no-op implementation)
 */
public class DOMConfigurator {
    // All methods are no-op implementations
}

Usage Examples:

import org.apache.log4j.xml.DOMConfigurator;

// XML configuration would be no-op
// DOMConfigurator.configure("log4j.xml"); // No-op

LogManager Configuration

Configuration methods available through LogManager. These methods are also no-op implementations.

/**
 * Get current loggers (returns empty enumeration)
 * @return Empty enumeration
 */
public static Enumeration<?> getCurrentLoggers();

/**
 * Shutdown logging system (no-op)
 */
public static void shutdown();

/**
 * Reset logging configuration (no-op)
 */
public static void resetConfiguration();

Usage Examples:

import org.apache.log4j.LogManager;
import java.util.Enumeration;

// Get current loggers (returns empty enumeration)
Enumeration<?> loggers = LogManager.getCurrentLoggers();

// Shutdown logging (no-op)
LogManager.shutdown();

// Reset configuration (no-op)
LogManager.resetConfiguration();

SLF4J Configuration Guide

Since log4j-over-slf4j delegates to SLF4J, actual configuration must be done through the SLF4J implementation.

Logback Configuration Example:

Create logback.xml in your classpath:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>
    
    <appender name="FILE" class="ch.qos.logback.core.FileAppender">
        <file>application.log</file>
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>
    
    <logger name="com.example" level="DEBUG"/>
    <logger name="org.springframework" level="INFO"/>
    
    <root level="INFO">
        <appender-ref ref="CONSOLE"/>
        <appender-ref ref="FILE"/>
    </root>
</configuration>

SLF4J Simple Configuration:

For development, you can use slf4j-simple with simplelogger.properties:

org.slf4j.simpleLogger.defaultLogLevel=info
org.slf4j.simpleLogger.log.com.example=debug
org.slf4j.simpleLogger.showDateTime=true
org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss:SSS
org.slf4j.simpleLogger.showThreadName=true
org.slf4j.simpleLogger.showLogName=true
org.slf4j.simpleLogger.showShortLogName=false

Migration Notes:

// Old Log4j 1.x configuration pattern
public class OldApp {
    static {
        // This would configure Log4j directly
        PropertyConfigurator.configure("log4j.properties");
    }
}

// New pattern with log4j-over-slf4j
public class NewApp {
    static {
        // Configuration is done through SLF4J implementation
        // No programmatic configuration needed - use logback.xml, etc.
        
        // These calls are no-op but maintain compatibility
        PropertyConfigurator.configure("log4j.properties"); // No-op
        BasicConfigurator.configure(); // No-op
    }
}

Configuration Migration

Guidelines for migrating from Log4j 1.x configuration to SLF4J-based configuration.

Log4j Properties to Logback XML:

# Old log4j.properties
log4j.rootLogger=INFO, console, file
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d [%t] %-5p %c - %m%n

Equivalent Logback configuration:

<configuration>
    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d [%t] %-5p %c - %m%n</pattern>
        </encoder>
    </appender>
    
    <root level="INFO">
        <appender-ref ref="console"/>
    </root>
</configuration>

Install with Tessl CLI

npx tessl i tessl/maven-org-slf4j--log4j-over-slf4j

docs

appenders-layouts.md

configuration.md

core-logging.md

diagnostic-contexts.md

index.md

level-management.md

tile.json