Unable to register unenforced exceptions using the log

I wrote a web application with various frameworks (jsf, Spring, Hibernate), and my log library is Logback and slf4j.

At the moment, I cannot display excluded exceptions (e.g. NullPointers) in the log file.

This is my logBack.xml file

<configuration debug="true">
    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${CATALINA_HOME}/logs/jsfDemo.log</file>

        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>jsfDemo.%d{yyyy-MM-dd}.log.zip</fileNamePattern>
            <maxHistory>30</maxHistory>
        </rollingPolicy>

        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{35} - %msg%n</pattern>
        </encoder>
    </appender> 

    <root level="DEBUG">         
        <appender-ref ref="FILE" />
    </root> 

</configuration>

when I execute these few lines of code with uc = null

public void nullPointerMethod(UserCredential uc){
        LOG.debug(">>login(uc)");

        if(uc == null){
            throw new NullPointerException();
        }else{
            //do something
        }

        LOG.debug("<<login(uc)");
    }

in logFile I only see

>>login(uc)

but I want to see stackTrace for NullPointer. What's wrong?

+4
source share
1 answer

You can use SLF4JBridgeHandler :

, , SLF4JBridgeHandler JUL . SLF4JBridgeHandler JUL, API- SLF4J

SLF4JBridgeHandler.install(); :

<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
    <resetJUL>true</resetJUL>
</contextListener>
+1

Source: https://habr.com/ru/post/1537722/


All Articles