Skip to content

Commit

Permalink
Remove StatusConsoleListener log level filtering (#2337, #2340)
Browse files Browse the repository at this point in the history
  • Loading branch information
panbingkun committed Mar 2, 2024
1 parent c542041 commit 28b70d1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ void StatusData_getFormattedStatus_should_be_used() {
}

@Test
void level_and_stream_should_be_honored() throws Exception {
void stream_should_be_honored() throws Exception {

// Create the listener.
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
final String encoding = "UTF-8";
final PrintStream printStream = new PrintStream(outputStream, false, encoding);
final StatusConsoleListener listener = new StatusConsoleListener(Level.WARN, printStream);

// First, log a message that is expected to be logged.
// log a message that is expected to be logged.
final RuntimeException expectedThrowable = new RuntimeException("expectedThrowable");
expectedThrowable.setStackTrace(new StackTraceElement[] {
new StackTraceElement("expectedThrowableClass", "expectedThrowableMethod", "expectedThrowableFile", 1)
Expand All @@ -71,29 +71,12 @@ void level_and_stream_should_be_honored() throws Exception {
expectedThrowable,
null)); // as set by `StatusLogger` itself

// Second, log a message that is expected to be discarded due to its insufficient level.
final RuntimeException discardedThrowable = new RuntimeException("discardedThrowable");
discardedThrowable.setStackTrace(new StackTraceElement[] {
new StackTraceElement("discardedThrowableClass", "discardedThrowableMethod", "discardedThrowableFile", 2)
});
final Message discardedMessage = MESSAGE_FACTORY.newMessage("discardedMessage");
listener.log(new StatusData(
null, // since ignored by `SimpleLogger`
Level.INFO,
discardedMessage,
discardedThrowable,
null)); // as set by `StatusLogger` itself

// Collect the output.
printStream.flush();
final String output = outputStream.toString(encoding);

// Verify the output.
assertThat(output)
.contains(expectedThrowable.getMessage())
.contains(expectedMessage.getFormattedMessage())
.doesNotContain(discardedThrowable.getMessage())
.doesNotContain(discardedMessage.getFormattedMessage());
assertThat(output).contains(expectedThrowable.getMessage()).contains(expectedMessage.getFormattedMessage());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,8 @@ public Level getStatusLevel() {
@Override
public void log(final StatusData data) {
requireNonNull(data, "data");
if (level.isLessSpecificThan(data.getLevel())) {
final String formattedStatus = data.getFormattedStatus();
stream.println(formattedStatus);
}
final String formattedStatus = data.getFormattedStatus();
stream.println(formattedStatus);
}

/**
Expand Down

0 comments on commit 28b70d1

Please sign in to comment.