5

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?

Leos Literak
  • 8,805
  • 19
  • 81
  • 156
  • 1
    Bugs and limitations in Logback. Reading the comments from Brice at https://stackoverflow.com/a/20407321/3080094 - you probably need Logback 1.0.3 at a minimum to get it working without source code changes. – vanOekel Jun 28 '18 at 11:37
  • Thank you, it looks promising. – Leos Literak Jun 28 '18 at 12:07
  • Upgrade to the current version did not help. I had to add a contextListener as recommended in the linked answer. – Leos Literak Jun 28 '18 at 15:07
  • 1
    The contextListener uses a LevelChangePropagator which is only available after 0.9.25 (and bug-fixed in 1.0.3), and you were using 0.9.20. I guess the upgrade and the contextListener combined did the trick? – vanOekel Jun 28 '18 at 17:49

1 Answers1

5

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.

Burt Beckwith
  • 75,342
  • 5
  • 143
  • 156
Leos Literak
  • 8,805
  • 19
  • 81
  • 156
  • Possible typo in JCL -> change to JUL. I am assuming the edit queue is full for that reason ;) – Matt Nov 22 '21 at 21:05