or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

bridge-handler.mdindex.mdlevel-translation.mdlogger-adapters.mdlogmanager-integration.md
tile.json

tessl/maven-org-apache-logging-log4j--log4j-jul

The Apache Log4j implementation of java.util.logging providing JUL to Log4j bridge functionality

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

To install, run

npx @tessl/cli install tessl/maven-org-apache-logging-log4j--log4j-jul@2.25.0

index.mddocs/

Apache Log4j JUL Adapter

The Apache Log4j JUL Adapter (log4j-jul) provides a bridge between Java Util Logging (JUL) and the Log4j logging framework. It allows applications and libraries using java.util.logging.Logger to seamlessly log through the Log4j API instead of the default Java logging implementation, offering better performance, more flexible configuration options, and advanced logging features.

Package Information

  • Package Name: log4j-jul
  • Package Type: maven
  • Language: Java
  • Maven Coordinates: org.apache.logging.log4j:log4j-jul:2.25.1
  • Installation: Add dependency to your pom.xml or build.gradle

Core Imports

import org.apache.logging.log4j.jul.LogManager;
import org.apache.logging.log4j.jul.Log4jBridgeHandler;
import org.apache.logging.log4j.jul.LevelTranslator;

Basic Usage

LogManager Replacement (Recommended)

For optimal performance, replace JUL's LogManager with Log4j's implementation:

// Set system property (typically in JVM args or system properties)
System.setProperty("java.util.logging.manager", "org.apache.logging.log4j.jul.LogManager");

// Use standard JUL API - it will be redirected to Log4j
java.util.logging.Logger logger = java.util.logging.Logger.getLogger("com.example");
logger.info("This message goes to Log4j");

Bridge Handler Alternative

For environments where LogManager replacement isn't feasible:

// Programmatic installation
import org.apache.logging.log4j.jul.Log4jBridgeHandler;

Log4jBridgeHandler.install(
    true,        // removeHandlersForRootLogger
    "_JUL",      // suffixToAppend (optional)
    true         // propagateLevels
);

// Or configure in logging.properties:
// handlers = org.apache.logging.log4j.jul.Log4jBridgeHandler
// org.apache.logging.log4j.jul.Log4jBridgeHandler.propagateLevels = true

Architecture

The log4j-jul adapter provides two main integration approaches:

  1. LogManager Replacement: Complete JUL-to-Log4j redirection for optimal performance
  2. Bridge Handler: Handler-based approach for constrained environments

The adapter automatically selects the appropriate logger implementation based on available Log4j components (API-only vs. Core).

Capabilities

LogManager Integration

Complete replacement of JUL's LogManager with Log4j-backed implementation providing transparent redirection of all JUL logging calls.

public class LogManager extends java.util.logging.LogManager {
    public LogManager();
    public Logger getLogger(String name);
    public Enumeration<String> getLoggerNames();
    public boolean addLogger(Logger logger);
}

LogManager Integration

Bridge Handler

JUL Handler that bridges log events to Log4j without requiring LogManager replacement, suitable for webapps and constrained environments.

public class Log4jBridgeHandler extends java.util.logging.Handler {
    public Log4jBridgeHandler();
    public Log4jBridgeHandler(boolean debugOutput, String suffixToAppend, boolean propagateLevels);
    public static void install(boolean removeHandlersForRootLogger, String suffixToAppend, boolean propagateLevels);
    public void publish(LogRecord record);
}

Bridge Handler

Level Translation

Bidirectional conversion between JUL and Log4j logging levels with support for custom levels and closest-match mapping.

public final class LevelTranslator {
    public static final Level FINEST;
    public static final Level CONFIG;
    public static Level toLevel(java.util.logging.Level level);
    public static java.util.logging.Level toJavaLevel(Level level);
}

Level Translation

Logger Adapters

Pluggable adapter system for different Log4j implementations (API-only vs. Core) with automatic selection and custom override capabilities.

public abstract class AbstractLoggerAdapter extends org.apache.logging.log4j.spi.AbstractLoggerAdapter<Logger> {
    protected LoggerContext getContext();
}

Logger Adapters

Configuration

System Properties

  • java.util.logging.manager - Set to org.apache.logging.log4j.jul.LogManager for LogManager approach
  • log4j.jul.LoggerAdapter - Override default logger adapter selection
  • log4j.jul.levelConverter - Use custom level converter implementation

JUL Configuration Properties

For Bridge Handler approach in logging.properties:

  • org.apache.logging.log4j.jul.Log4jBridgeHandler.suffixToAppend - Suffix for JUL logger names
  • org.apache.logging.log4j.jul.Log4jBridgeHandler.propagateLevels - Auto-propagate Log4j levels to JUL
  • org.apache.logging.log4j.jul.Log4jBridgeHandler.sysoutDebug - Enable debug output

Dependencies

  • Required: log4j-api
  • Optional: log4j-core (enables enhanced functionality and CoreLogger features)
  • Compatible: All Java versions supported by Log4j 2.x

Types

public interface LevelConverter {
    Level toLevel(java.util.logging.Level javaLevel);
    java.util.logging.Level toJavaLevel(Level level);
}

public final class Constants {
    public static final String LOGGER_ADAPTOR_PROPERTY = "log4j.jul.LoggerAdapter";
    public static final String LEVEL_CONVERTER_PROPERTY = "log4j.jul.levelConverter";
}