Skip to content

Commit

Permalink
More detailed logging from checkStaticState
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Nied <[email protected]>
  • Loading branch information
peternied committed Feb 13, 2024
1 parent ba385e4 commit 0663818
Showing 1 changed file with 32 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.math.BigInteger;
import java.net.InetAddress;
import java.net.UnknownHostException;
Expand All @@ -170,6 +172,7 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BooleanSupplier;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.IntFunction;
import java.util.function.Predicate;
import java.util.function.Supplier;
Expand Down Expand Up @@ -639,15 +642,36 @@ protected static void checkStaticState(boolean afterClass) throws Exception {
try {
// ensure that there are no status logger messages which would indicate a problem with our Log4j usage; we map the
// StatusData instances to Strings as otherwise their toString output is useless

final Function<StatusData, String> statusToString = (statusData) -> {
try (final StringWriter sw = new StringWriter(); final PrintWriter pw = new PrintWriter(sw)) {

pw.print(statusData.getLevel());
pw.print(":");
pw.print(statusData.getMessage().getFormattedMessage());

if (statusData.getStackTraceElement() != null) {
final var messageSource = statusData.getStackTraceElement();

pw.println();
pw.println("Source:");
pw.println(messageSource.getFileName() + "@" + messageSource.getLineNumber());
}

if (statusData.getThrowable() != null) {
pw.println();
pw.println("Throwable:");
pw.println(statusData.getThrowable().toString());
statusData.getThrowable().printStackTrace(pw);
}
return sw.toString();
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
};

assertThat(
statusData.stream()
.map(
status -> status.getLevel()
+ ": "
+ status.getMessage()
+ (status.getThrowable() == null ? "" : "\r\n\r\nTrowable:\r\n" + status.getThrowable().toString())
)
.collect(Collectors.joining("\r\n")),
statusData.stream().map(statusToString::apply).collect(Collectors.joining("\r\n")),
statusData.stream().map(status -> status.getMessage().getFormattedMessage()).collect(Collectors.toList()),
empty()
);
Expand Down

0 comments on commit 0663818

Please sign in to comment.