The Apache Log4j implementation of java.util.logging providing JUL to Log4j bridge functionality
—
The LogManager integration provides complete replacement of JUL's LogManager with Log4j's implementation, offering optimal performance by redirecting all JUL logging calls directly to Log4j without the overhead of handler-based bridging.
Enable LogManager integration by setting the system property:
System.setProperty("java.util.logging.manager", "org.apache.logging.log4j.jul.LogManager");Or via JVM arguments:
-Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManagerOnce configured, all standard JUL API calls are transparently redirected to Log4j:
// Standard JUL API - automatically uses Log4j
java.util.logging.Logger logger = java.util.logging.Logger.getLogger("com.example.MyClass");
// All logging methods work as expected
logger.severe("Error message");
logger.warning("Warning message");
logger.info("Info message");
logger.fine("Debug message");
logger.finest("Trace message");
// Parameterized messages
logger.log(java.util.logging.Level.INFO, "Processing {0} items", 42);
// Exception logging
try {
// some operation
} catch (Exception e) {
logger.log(java.util.logging.Level.SEVERE, "Operation failed", e);
}The LogManager automatically selects the most appropriate logger adapter:
log4j.jul.LoggerAdapter property is set// Override adapter selection
System.setProperty("log4j.jul.LoggerAdapter", "com.example.CustomLoggerAdapter");public class LogManager extends java.util.logging.LogManager {
/**
* Creates new LogManager instance with automatic adapter selection.
* Selects CustomAdapter -> CoreLoggerAdapter -> ApiLoggerAdapter (fallback).
*/
public LogManager();
/**
* Returns logger for the given name, creating if necessary.
* Handles recursive calls and delegates to the selected adapter.
*
* @param name the logger name
* @return Logger instance backed by Log4j
*/
public Logger getLogger(String name);
/**
* Returns enumeration of all logger names from the adapter context.
*
* @return enumeration of logger names
*/
public Enumeration<String> getLoggerNames();
/**
* Always returns false to prevent registration of non-bridged loggers.
* All loggers must be obtained through getLogger(name).
*
* @param logger the logger to add
* @return always false
*/
public boolean addLogger(Logger logger);
}public final class Constants {
/**
* Property name for overriding the AbstractLoggerAdapter implementation.
* Set to fully qualified class name with default constructor.
*/
public static final String LOGGER_ADAPTOR_PROPERTY = "log4j.jul.LoggerAdapter";
}The LogManager creates different logger implementations based on available Log4j components:
CoreLoggerAdapter creating CoreLogger instancesApiLoggerAdapter creating ApiLogger instancessetLevel() and getParent() have limitationsThe LogManager implementation is fully thread-safe:
ThreadLocal<Set<String>> to detect and prevent recursive logger creationNoOpLogger for recursive calls to prevent infinite loopsThe LogManager gracefully handles various error conditions:
// Recursive calls are detected and logged
logger.warn("Recursive call to getLogger for {} ignored.", name);
// Custom adapter loading failures fall back to default
logger.error("Specified LoggerAdapter [{}] is incompatible.", className, exception);The LogManager respects all Log4j configuration settings:
When migrating from standard JUL to LogManager integration:
Install with Tessl CLI
npx tessl i tessl/maven-org-apache-logging-log4j--log4j-jul