Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logback does not log JUL fine level

I am fixing a legacy JSF application running on tomcat 7.

UserAccessBB.java

package beans;
import java.util.logging.Level;
import java.util.logging.Logger;

public class UserAccessBB {
private static final Logger LOG = 
Logger.getLogger(UserAccessBB.class.getName());

public UserAccessBB() {
    LOG.fine("UserAccessBB");

logback.xml

<logger name="beans" level="TRACE" additivity="false">
    <appender-ref ref="STDOUT" />
    <appender-ref ref="FILE" />
</logger>
<root level="INFO">
    <appender-ref ref="STDOUT" />
    <appender-ref ref="FILE" />
</root>

maven

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jul-to-slf4j</artifactId>
        <version>${slf4j.version}</version>
    </dependency>
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>0.9.20</version>
    </dependency>

The file is copied to WEB-INF/classes

The log file contains only INFO and higher level logs from this class. Lower levels are printed only when I modify the root logger. Where is the issue?

like image 950
Leos Literak Avatar asked Jun 28 '18 07:06

Leos Literak


1 Answers

For future reference and googlers:

To Logback be able to propagate its configuration to JUL (java.util.logging) it is neccessary to add

<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
    <!-- reset all previous level configurations of all j.u.l. loggers -->
    <resetJUL>true</resetJUL>
</contextListener>

and use the current version. Cudos to @vanOekel. See https://stackoverflow.com/a/20407321/1639556 for details.

like image 160
Leos Literak Avatar answered Nov 04 '22 18:11

Leos Literak