private static void render(OutputStream out, Collection<LogRecord> log) throws IOException {
        var json = factory.createGenerator(out);
        json.writeStartObject();
        json.writeArrayFieldStart("logRecords");
        for (LogRecord record : log) {
            String message = record.getMessage() == null ? "" : record.getMessage();
            if (record.getThrown() != null) {
                ByteArrayOutputStream buffer = new ByteArrayOutputStream();
                record.getThrown().printStackTrace(new PrintStream(buffer));
                message += (message.isEmpty() ? "" : "\n") + buffer;
            }
            json.writeStartObject();
            json.writeNumberField("id", record.getSequenceNumber());
            json.writeNumberField("at", record.getMillis());
            json.writeStringField("type", typeOf(record.getLevel()));
            json.writeStringField("message", message);
            json.writeEndObject();
        }
        json.writeEndArray();
        json.writeEndObject();
        json.close();
    }
@author valerijf
@author jonmv
@author mortent
vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/TestRunnerHandler.java