logback / LOGBACK-1612 [Open] jul LevelChangePropagator is inconsistent with SLF4JBridgeHandler
============================== Here's what changed in this issue in the last few minutes. This issue has been created This issue is now assigned to you. View or comment on issue using this link https://jira.qos.ch/browse/LOGBACK-1612 ============================== Issue created ------------------------------ Yonathan Randolph created this issue on 15/Jan/22 7:36 AM Summary: jul LevelChangePropagator is inconsistent with SLF4JBridgeHandler Issue Type: Bug Assignee: Logback dev list Components: logback-classic Created: 15/Jan/22 7:36 AM Environment: jre 1.8 jul-to-slf4j 1.7.26 (but [SLF4JBridgeHandler|https://github.com/qos-ch/slf4j/blob/v_1.7.33/jul-to-slf4j/src/main/java/org/slf4j/bridge/SLF4JBridgeHandler.java#L227-L237] hasn't changed much as of 1.7.33) logback-classic 1.2.3 (but [JULHelper|https://github.com/qos-ch/logback/blob/v_1.8.0-alpha1/logback-classic/src/main/java/ch/qos/logback/classic/jul/JULHelper.java#L38-L51] hasn't changed much as of 1.8.0) Log messages are sent using java.util.logging. SLF4JBridgeHandler and LevelChangePropagator are enabled (I was running PlayFramework which does this automatically) logback.xml contains <logger name="com.sun.mail.util" level="DEBUG"/> Labels: logging Priority: Minor Reporter: Yonathan Randolph Description: LevelChangePropagator is inconsistent with jul-to-slf4j for intermediate values FINER, CONFIG, SEVERE, and any other custom jul Level that you construct. When you logger.finer(), it becomes DEBUG, but when you set the level to DEBUG, then logger.finer() messages disappear. When I configured the level for the logger com.sun.mail.util to ALL in my logback.xml, I observed log messages with level DEBUG. But when I configured the logger's level to DEBUG in logback.xml, the logger became disabled! The [library I was observing|https://github.com/eclipse-ee4j/angus-mail/blob/1.0.0/core/src/main/java/com/sun/mail/util/SocketFetcher.java#L147-L149] used java.util.logging and conditionally did {noformat} if (logger.isLoggable(Level.FINER)) logger.finer(""){noformat} h2. Current implementations jul-to-slf4j's [SLF4JBridgeHandler.callPlainSLF4JLogger|https://github.com/qos-ch/slf4j/blob/v_1.7.33/jul-to-slf4j/src/main/java/org/slf4j/bridge/SLF4JBridgeHandler.java#L227-L237]: given jul level _x_, it maps to a slf4j level _y_: * _x_ ≤ FINEST = 300 → TRACE * FINEST < _x_ ≤ FINE = 500 → DEBUG ** including FINER = 400 * FINE < _x_ ≤ INFO = 800 → INFO ** including CONFIG = 700 * INFO < _x_ ≤ WARNING = 900 → WARN * WARNING < _x_ → ERROR ** including SEVERE = 1000 -> TRACE LevelChangePropagator's [JULHelper.asJULLevel|https://github.com/qos-ch/logback/blob/v_1.8.0-alpha1/logback-classic/src/main/java/ch/qos/logback/classic/jul/JULHelper.java#L38-L51]: given slf4j level y, it maps to a jul level _x_. * slf4j TRACE → jul FINEST * DEBUG → FINE * INFO → INFO * WARN → WARNING * ERROR → SEVERE * OFF → OFF The problem is that these _x_ values are all at the top of the jul-to-slf4j intervals, but [java.util.logging.Logger.isLoggable|https://github.com/openjdk/jdk/blob/jdk-19+5/src/java.logging/share/classes/java/util/logging/Logger.java#L2035-L2041] will reject any message whose level is less than this _x_. So jul-to-slf4j will log a FINER message as DEBUG, but if you set the slf4j level to DEBUG, then FINER messages are rejected. h2. Proposed implementation: I think the correct behavior is for LevelChangePropagator to return the minimum value in each jul-to-slf4j interval rather than the maximum value, so that the values will be consistent * slf4j TRACE → jul Integer.MIN_VALUE * DEBUG → FINEST + 1 = 301 * INFO → FINE + 1 = 501 * WARN → INFO + 1 = 801 * ERROR → WARNING + 1 = 901 * OFF → OFF (this is special-cased in [java.util.logging.Logger.isLoggable|https://github.com/openjdk/jdk/blob/jdk-19+5/src/java.logging/share/classes/java/util/logging/Logger.java#L2035-L2041]) ============================== This message was sent by Atlassian Jira (v8.8.0#808000-sha1:e2c7e59) _______________________________________________ logback-dev mailing list logback-dev@qos.ch http://mailman.qos.ch/mailman/listinfo/logback-dev