Skip to content

Commit 83702bb

Browse files
cookiejack15ppkarwaszvy
authored
Fix SLF4JLogger.atFatal() returning Level.TRACE instead of Level.FATAL (#4089)
Co-authored-by: Piotr P. Karwasz <pkarwasz-github@apache.org> Co-authored-by: Volkan Yazıcı <volkan@yazi.ci>
1 parent 7e6cce5 commit 83702bb

3 files changed

Lines changed: 30 additions & 1 deletion

File tree

log4j-to-slf4j/src/main/java/org/apache/logging/slf4j/SLF4JLogger.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ public LogBuilder atError() {
363363

364364
@Override
365365
public LogBuilder atFatal() {
366-
return atLevel(Level.TRACE);
366+
return atLevel(Level.FATAL);
367367
}
368368

369369
@Override

log4j-to-slf4j/src/test/java/org/apache/logging/slf4j/LogBuilderTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,20 @@ void testLevelThreshold(final Consumer<LogBuilder> consumer) {
103103
assertThat(list.strList).hasSize(1);
104104
list.strList.clear();
105105
}
106+
107+
/**
108+
* Verifies that {@code atFatal()} delegates to {@code atLevel(Level.FATAL)}
109+
* and not {@code atLevel(Level.TRACE)}.
110+
*
111+
* @see <a href="https://github.com/apache/logging-log4j2/issues/4068">#4068</a>
112+
*/
113+
@ParameterizedTest
114+
@MethodSource("logBuilderMethods")
115+
void atFatal_should_log_at_error_level(final Consumer<LogBuilder> consumer) {
116+
consumer.accept(logger.atFatal());
117+
assertThat(list.strList)
118+
.as("atFatal() must produce a log event (SLF4J ERROR equivalent)")
119+
.hasSize(1);
120+
list.strList.clear();
121+
}
106122
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<entry xmlns="https://logging.apache.org/xml/ns"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="
5+
https://logging.apache.org/xml/ns
6+
https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
7+
type="fixed">
8+
<issue id="4068" link="https://github.com/apache/logging-log4j2/issues/4068"/>
9+
<issue id="4089" link="https://github.com/apache/logging-log4j2/pull/4089"/>
10+
<description format="asciidoc">
11+
Fixed `SLF4JLogger.atFatal()` returning `atLevel(Level.TRACE)` instead of `atLevel(Level.FATAL)`, which caused FATAL log events to be silently discarded when using the fluent API through the `log4j-to-slf4j` bridge.
12+
</description>
13+
</entry>

0 commit comments

Comments
 (0)