Skip to content

Commit 0407c14

Browse files
committed
[FOLLOWUP] Fix StatusLogger log level filtering when debug mode is enabled
1 parent c542041 commit 0407c14

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

log4j-api/src/main/java/org/apache/logging/log4j/status/StatusConsoleListener.java

+33-2
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,28 @@ public class StatusConsoleListener implements StatusListener {
4444
// `volatile` is necessary to correctly read the `stream` without holding the lock
4545
private volatile PrintStream stream;
4646

47+
// whether or not enables debug mode
48+
private final boolean debugEnabled;
49+
4750
/**
4851
* Constructs a {@link StatusConsoleListener} instance writing to {@link System#out} using the supplied level.
4952
*
5053
* @param level the level of status messages that should appear on the console
5154
* @throws NullPointerException on null {@code level}
5255
*/
5356
public StatusConsoleListener(final Level level) {
54-
this(level, System.out);
57+
this(level, false);
58+
}
59+
60+
/**
61+
* Constructs a {@link StatusConsoleListener} instance writing to {@link System#out} using the supplied level.
62+
*
63+
* @param level the level of status messages that should appear on the console
64+
* @param debugEnabled whether or not enables debug mode
65+
* @throws NullPointerException on null {@code level}
66+
*/
67+
public StatusConsoleListener(final Level level, final boolean debugEnabled) {
68+
this(level, System.out, debugEnabled);
5569
}
5670

5771
/**
@@ -65,8 +79,25 @@ public StatusConsoleListener(final Level level) {
6579
* @throws NullPointerException on null {@code level} or {@code stream}
6680
*/
6781
public StatusConsoleListener(final Level level, final PrintStream stream) {
82+
this(level, stream, false);
83+
}
84+
85+
/**
86+
* Constructs a {@link StatusConsoleListener} instance using the supplied level and stream.
87+
* <p>
88+
* Make sure not to use a logger stream of some sort to avoid creating an infinite loop of indirection!
89+
* </p>
90+
*
91+
* @param level the level of status messages that should appear on the console
92+
* @param stream the stream to write to
93+
* @param debugEnabled whether or not enables debug mode
94+
* @throws NullPointerException on null {@code level} or {@code stream}
95+
*/
96+
public StatusConsoleListener(final Level level, final PrintStream stream,
97+
final boolean debugEnabled) {
6898
this.initialLevel = this.level = requireNonNull(level, "level");
6999
this.initialStream = this.stream = requireNonNull(stream, "stream");
100+
this.debugEnabled = debugEnabled;
70101
}
71102

72103
/**
@@ -134,7 +165,7 @@ public Level getStatusLevel() {
134165
@Override
135166
public void log(final StatusData data) {
136167
requireNonNull(data, "data");
137-
if (level.isLessSpecificThan(data.getLevel())) {
168+
if (debugEnabled || level.isLessSpecificThan(data.getLevel())) {
138169
final String formattedStatus = data.getFormattedStatus();
139170
stream.println(formattedStatus);
140171
}

log4j-api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,8 @@ private static final class InstanceHolder {
526526
StatusLogger.class.getSimpleName(),
527527
ParameterizedNoReferenceMessageFactory.INSTANCE,
528528
Config.getInstance(),
529-
new StatusConsoleListener(Config.getInstance().fallbackListenerLevel));
529+
new StatusConsoleListener(Config.getInstance().fallbackListenerLevel,
530+
Config.getInstance().debugEnabled));
530531
}
531532

532533
/**

0 commit comments

Comments
 (0)