void (boolean success, @NotNull String testName) { String buffer; synchronized (myBuffer) { buffer = success || myBuffer.isEmpty() ? null : myBuffer.toString(); myBuffer.setLength(0); } if (buffer != null) { if (mySplitTestLogs) { Path logDir = getTestLogDir().resolve(SPLIT_LOGS_SUBDIR); Path logFile = FileUtil.findSequentNonexistentFile(logDir.toFile(), FileUtil.sanitizeFileName(testName), "log").toPath(); try { Files.createDirectories(logDir); Files.writeString(logFile, buffer); String headerFooter = StringUtil.repeat("=", 80); buffer = "\n" + headerFooter + "\nLog saved to: " + logFile.getFileName() + "\n (" + logFile + ")" + "\n" + headerFooter + "\n"; } catch (IOException e) { buffer += "\nError writing split log, disabling splitting: " + logFile + '\n' + e; mySplitTestLogs = false; } } if (System.getenv("TEAMCITY_VERSION") != null) { String finalBuffer = buffer; TeamCityLogger.block("DEBUG log", () -> System.out.println(finalBuffer) ); } else { // mark each line in IDEA console with this hidden mark to be able to fold it automatically List<String> lines = LineTokenizer.tokenizeIntoList(buffer, false, false); if (!lines.get(0).startsWith("\n")) lines.set(0, "\n" + lines.get(0)); System.err.println(String.join(FAILED_TEST_DEBUG_OUTPUT_MARKER + "\n", lines)); } } }