The Apache Log4j implementation of java.util.logging providing JUL to Log4j bridge functionality
npx @tessl/cli install tessl/maven-org-apache-logging-log4j--log4j-jul@2.25.0The 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.
org.apache.logging.log4j:log4j-jul:2.25.1pom.xml or build.gradleimport org.apache.logging.log4j.jul.LogManager;
import org.apache.logging.log4j.jul.Log4jBridgeHandler;
import org.apache.logging.log4j.jul.LevelTranslator;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");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 = trueThe log4j-jul adapter provides two main integration approaches:
The adapter automatically selects the appropriate logger implementation based on available Log4j components (API-only vs. Core).
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);
}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);
}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);
}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();
}java.util.logging.manager - Set to org.apache.logging.log4j.jul.LogManager for LogManager approachlog4j.jul.LoggerAdapter - Override default logger adapter selectionlog4j.jul.levelConverter - Use custom level converter implementationFor Bridge Handler approach in logging.properties:
org.apache.logging.log4j.jul.Log4jBridgeHandler.suffixToAppend - Suffix for JUL logger namesorg.apache.logging.log4j.jul.Log4jBridgeHandler.propagateLevels - Auto-propagate Log4j levels to JULorg.apache.logging.log4j.jul.Log4jBridgeHandler.sysoutDebug - Enable debug outputpublic 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";
}