public static void saveExistingErrors(
        final File markFile,
        final AtomicBuffer errorBuffer,
        final PrintStream logger,
        final String errorFilePrefix)
    {
        try
        {
            final ByteArrayOutputStream baos = new ByteArrayOutputStream();
            final int observations = printErrorLog(errorBuffer, new PrintStream(baos, false, "US-ASCII"));
            if (observations > 0)
            {
                final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss-SSSZ");
                final File errorLogFile = new File(
                    markFile.getParentFile(), errorFilePrefix + '-' + dateFormat.format(new Date()) + "-error.log");

                if (null != logger)
                {
                    logger.println("WARNING: existing errors saved to: " + errorLogFile);
                }

                try (FileOutputStream out = new FileOutputStream(errorLogFile))
                {
                    baos.writeTo(out);
                }
            }
        }
        catch (final Exception ex)
        {
            LangUtil.rethrowUnchecked(ex);
        }
    }
@Test
    void saveExistingErrorsIsANoOpIfErrorBufferIsEmpty()
    {
        final File markFile = tempDir.resolve("mark.dat").toFile();
        final UnsafeBuffer errorBuffer = new UnsafeBuffer(new byte[0]);
        final PrintStream logger = mock(PrintStream.class);
        final String errorFilePrefix = "test-error-";

        CommonContext.saveExistingErrors(markFile, errorBuffer, logger, errorFilePrefix);

        verifyNoInteractions(logger);
    }