or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

appenders.mdbuilders.mdconfiguration.mdcontext.mdindex.mdlayouts.mdlogging.mdspi.md
tile.json

tessl/maven-org-apache-logging-log4j--log4j-1-2-api

The Apache Log4j 1.x Compatibility API providing a bridge to Log4j 2.x implementations

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/org.apache.logging.log4j/log4j-1.2-api@2.25.x

To install, run

npx @tessl/cli install tessl/maven-org-apache-logging-log4j--log4j-1-2-api@2.25.0

index.mddocs/

Log4j 1.x Compatibility API

Overview

The Apache Log4j 1.x Compatibility API provides a seamless bridge between legacy Log4j 1.x applications and the modern Log4j 2.x infrastructure. This compatibility layer allows existing applications using Log4j 1.x syntax to work without code changes while benefiting from Log4j 2.x's improved performance, security, and features.

Package Information

  • Package: org.apache.logging.log4j:log4j-1.2-api
  • Version: 2.25.1
  • Type: Library
  • Language: Java
  • License: Apache-2.0

Installation

Maven

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-1.2-api</artifactId>
    <version>2.25.1</version>
</dependency>

Gradle

implementation 'org.apache.logging.log4j:log4j-1.2-api:2.25.1'

Core Imports

// Primary logging classes
import org.apache.log4j.Logger;
import org.apache.log4j.LogManager;
import org.apache.log4j.Level;

// Configuration
import org.apache.log4j.PropertyConfigurator;
import org.apache.log4j.xml.DOMConfigurator;

// Appenders and layouts
import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.FileAppender;
import org.apache.log4j.PatternLayout;

// Thread context
import org.apache.log4j.MDC;
import org.apache.log4j.NDC;

Basic Usage

Simple Logging

import org.apache.log4j.Logger;

public class MyClass {
    private static final Logger logger = Logger.getLogger(MyClass.class);
    
    public void doSomething() {
        logger.info("Starting operation");
        try {
            // Your code here
            logger.debug("Operation completed successfully");
        } catch (Exception e) {
            logger.error("Operation failed", e);
        }
    }
}

Configuration

import org.apache.log4j.PropertyConfigurator;
import org.apache.log4j.xml.DOMConfigurator;

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

// Configure from XML file
DOMConfigurator.configure("log4j.xml");

Thread Context

import org.apache.log4j.MDC;
import org.apache.log4j.NDC;

// Mapped Diagnostic Context
MDC.put("userId", "john123");
MDC.put("sessionId", "session456");

// Nested Diagnostic Context
NDC.push("WebService");
NDC.push("UserOperation");

Architecture

The Log4j 1.x Compatibility API consists of several key architectural components:

  • Logging Core: Primary logging classes that maintain Log4j 1.x interface while delegating to Log4j 2.x
  • Configuration: Multiple configuration approaches supporting both properties and XML formats
  • Appenders: Output destinations with full Log4j 1.x compatibility
  • Layouts: Message formatting with pattern-based and simple layouts
  • Thread Context: Thread-local diagnostic information storage
  • SPI Extension Points: Interfaces for custom extensions and plugins

Capabilities

Core Logging

Primary logging interfaces including Logger, LogManager, and Level classes. Provides the main entry points for application logging with full Log4j 1.x compatibility.

Logger logger = Logger.getLogger(MyClass.class);
logger.info("Application started");
logger.error("Error occurred", exception);

Configuration Management

Configuration loading and management through PropertyConfigurator, DOMConfigurator, and programmatic configuration. Supports both traditional Log4j 1.x configuration formats.

PropertyConfigurator.configure("log4j.properties");
DOMConfigurator.configure("log4j.xml");
BasicConfigurator.configure();

Appenders and Output

Output destinations including ConsoleAppender, FileAppender, RollingFileAppender, and custom appenders. Manages where log messages are written with full configurability.

ConsoleAppender appender = new ConsoleAppender(new PatternLayout("%d %p %c - %m%n"));
logger.addAppender(appender);

Layouts and Formatting

Message formatting through PatternLayout, SimpleLayout, and custom layouts. Controls how log messages are formatted for output.

PatternLayout layout = new PatternLayout("%d{ISO8601} [%t] %-5p %c{1} - %m%n");
SimpleLayout simpleLayout = new SimpleLayout();

Thread Context

Thread-local diagnostic context through MDC (Mapped Diagnostic Context) and NDC (Nested Diagnostic Context). Enables context-aware logging across application threads.

MDC.put("userId", "user123");
MDC.put("requestId", "req456");
NDC.push("operation");

Configuration Builders

Programmatic configuration builders that integrate with Log4j 2.x configuration system while maintaining Log4j 1.x compatibility.

AppenderBuilder<?> builder = new ConsoleAppenderBuilder<>();
Filter filter = new LevelRangeFilterBuilder().build();

SPI and Extension Points

Service Provider Interface classes including LoggerRepository, ErrorHandler, Filter, and other extension points for custom functionality.

public interface ErrorHandler {
    void error(String message, Exception ex, int errorCode);
    void setAppender(Appender appender);
}