private static void formatStackTraceAsArray()

in ecs-logging-core/src/main/java/co/elastic/logging/EcsJsonSerializer.java [278:310]


    private static void formatStackTraceAsArray(StringBuilder builder, CharSequence stackTrace) {
        builder.append(NEW_LINE);

        // splits the stackTrace by new lines
        Matcher matcher = NEW_LINE_PATTERN.matcher(stackTrace);
        if (matcher.find()) {
            int index = 0;
            do {
                int start = matcher.start();
                int end = matcher.end();
                if (index == 0 && index == start && start == end) {
                    // no empty leading substring included for zero-width match
                    // at the beginning of the input char sequence.
                    continue;
                }

                // append non-last line
                appendStackTraceLine(builder, stackTrace, index, start);
                builder.append(',');
                builder.append(NEW_LINE);
                index = end;
            } while (matcher.find());

            int length = stackTrace.length();
            if (index < length) {
                // append remaining line
                appendStackTraceLine(builder, stackTrace, index, length);
            }
        } else {
            // no newlines found, add entire stack trace as single element
            appendStackTraceLine(builder, stackTrace, 0, stackTrace.length());
        }
    }