@@ -44,14 +44,28 @@ public class StatusConsoleListener implements StatusListener {
44
44
// `volatile` is necessary to correctly read the `stream` without holding the lock
45
45
private volatile PrintStream stream ;
46
46
47
+ // whether or not enables debug mode
48
+ private final boolean debugEnabled ;
49
+
47
50
/**
48
51
* Constructs a {@link StatusConsoleListener} instance writing to {@link System#out} using the supplied level.
49
52
*
50
53
* @param level the level of status messages that should appear on the console
51
54
* @throws NullPointerException on null {@code level}
52
55
*/
53
56
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 );
55
69
}
56
70
57
71
/**
@@ -65,8 +79,25 @@ public StatusConsoleListener(final Level level) {
65
79
* @throws NullPointerException on null {@code level} or {@code stream}
66
80
*/
67
81
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 ) {
68
98
this .initialLevel = this .level = requireNonNull (level , "level" );
69
99
this .initialStream = this .stream = requireNonNull (stream , "stream" );
100
+ this .debugEnabled = debugEnabled ;
70
101
}
71
102
72
103
/**
@@ -134,7 +165,7 @@ public Level getStatusLevel() {
134
165
@ Override
135
166
public void log (final StatusData data ) {
136
167
requireNonNull (data , "data" );
137
- if (level .isLessSpecificThan (data .getLevel ())) {
168
+ if (debugEnabled || level .isLessSpecificThan (data .getLevel ())) {
138
169
final String formattedStatus = data .getFormattedStatus ();
139
170
stream .println (formattedStatus );
140
171
}
0 commit comments