How do I configure log4j to send log events to java.util.logging using JULAppender?

Tags: , , ,

I am familiar with the java.util.logging (JUL) framework, I use it extensively. Recently, I started using a library that does its logging through log4j. When I start my application I now get the following printed on the console:

log4j:WARN No appenders could be found for logger (com.example.thirdparty.Library).
log4j:WARN Please initialize the log4j system properly.

It appears that log4j has a solution for this: JULAppender which will send everything logged with log4j to the logging framework that I use.

I can’t find any examples that show me how to configure log4j to use this appender.


The standard way of configuring log4j is to create log4j.xml in the root of the classpath. Here are contents of that file configured for JULAppender:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="">
    <appender name="jul" class="org.apache.log4j.JulAppender"> 
        <layout class="org.apache.log4j.PatternLayout"> 
            <param name="ConversionPattern" value="%d %-5p %c - %m%n "/> 
        <priority value="all" /> 
        <appender-ref ref="jul" /> 

Source: stackoverflow