Search code examples
javaspring-bootjul-to-slf4j

Project inside SpringBoot 2.6.0 working, forced to use Log4J1 and JCL redirect working but JUL not


I have a project whereby the latest build is now SpringBoot 2.6.0 (and older one is a WAR for Tomcat 8). I have a sub-project/component that connects to stuff that forces me to use Log4J1. Logback was working beautifully but I've had to disable it (due to Log4J2 eclipsing and breaking the code that requires Log4J1 and also a new vendor component requiring Log4J2 as well).

I've:

  1. disabled Logback by excluding spring-boot-starter-logging
  2. Added a dependency for spring-boot-starter-log4j

Via the Dependency hierarchy tab (in Eclipse) I can see the jcl and jul libraries and in my logs (Console and File appenders) it is clear that SpringBoot (jcl stuff) and any of my project jcl calls are logged, but any JUL are not.

I've read tons of different tickets on here, gleaned together the info and got to this point. So it's all good except I cannot seem to pipe the JUL calls to the Log4J1 setup.

I can see jul-to-slf4j brought in via spring-boot-starter-log4j.

I thought I'd write here as I'm sure it's something simple I've missed but I think I've been staring at it for too long this afternoon! :)

What have I missed?

        <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-log4j</artifactId>
        <version>1.3.8.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.7.32</version>
    </dependency>   
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jcl-over-slf4j</artifactId>
        <version>1.7.32</version>
    </dependency>   

Solution

  • I got the JUL bits piping via adding this:

    SLF4JBridgeHandler.install();
    java.util.logging.LogManager.getLogManager().getLogger("").setLevel( Level.INFO);
    

    Which I found on question JUL to SLF4J Bridge