Avoid redirecting System.out

GitOrigin-RevId: 451a89190f2089b3053763f41a96d84fa5c3093e
This commit is contained in:
Tagir Valeev
2022-09-08 21:30:56 +00:00
committed by intellij-monorepo-bot
parent b90e7ecd88
commit 339e3a45d4
2 changed files with 9 additions and 12 deletions
@@ -124,6 +124,10 @@ public final class TestLoggerFactory implements Logger.Factory {
}
public static void dumpLogToStdout(@NotNull String testStartMarker) {
dumpLogTo(testStartMarker, System.out);
}
public static void dumpLogTo(@NotNull String testStartMarker, PrintStream out) {
Path logFile = getTestLogDir().resolve(LOG_FILE_NAME);
if (Files.exists(logFile)) {
try {
@@ -142,12 +146,12 @@ public final class TestLoggerFactory implements Logger.Factory {
logText = Files.readString(logFile);
}
System.out.println("\n\nIdea Log:");
out.println("\n\nIdea Log:");
Pattern logStart = Pattern.compile("[\\d\\-, :\\[\\]]+(DEBUG|INFO|ERROR) - ");
for (String line : StringUtil.splitByLines(logText.substring(Math.max(0, logText.lastIndexOf(testStartMarker))))) {
Matcher matcher = logStart.matcher(line);
int lineStart = matcher.lookingAt() ? matcher.end() : 0;
System.out.println(line.substring(lineStart));
out.println(line.substring(lineStart));
}
}
catch (IOException e) {
@@ -825,16 +825,9 @@ class ModuleBridgesTest {
}
fun catchLog(): String {
val prev = System.out
return try {
val outCatcher = OutCatcher(System.out)
System.setOut(outCatcher)
TestLoggerFactory.dumpLogToStdout(logLine)
outCatcher.catcher
}
finally {
System.setOut(prev)
}
val outCatcher = OutCatcher(System.out)
TestLoggerFactory.dumpLogTo(logLine, outCatcher)
return outCatcher.catcher
}
}
}