logback-android/src/main/java/ch/qos/logback/core/helpers/Transform.java
public static void appendEscapingCDATA(StringBuilder output, String str) {
    if (str == null) {
      return;
    }

    int end = str.indexOf(CDATA_END);

    if (end < 0) {
      output.append(str);

      return;
    }

    int start = 0;

    while (end > -1) {
      output.append(str.substring(start, end));
      output.append(CDATA_EMBEDED_END);
      start = end + CDATA_END_LEN;

      if (start < str.length()) {
        end = str.indexOf(CDATA_END, start);
      } else {
        return;
      }
    }

    output.append(str.substring(start));
  }
public static void appendEscapingCDATA(StringBuilder output, String str) {
    if (str == null) {
      return;
    }

    int end = str.indexOf(CDATA_END);

    if (end < 0) {
      output.append(str);

      return;
    }

    int start = 0;

    while (end > -1) {
      output.append(str.substring(start, end));
      output.append(CDATA_EMBEDED_END);
      start = end + CDATA_END_LEN;

      if (start < str.length()) {
        end = str.indexOf(CDATA_END, start);
      } else {
        return;
      }
    }

    output.append(str.substring(start));
  }
Ensures that embedded CDEnd strings (]]&gt;) are handled properly within
message, NDC and throwable tag text.

@param output
Writer. The initial CDSutart (&lt;![CDATA[) and final CDEnd (]]&gt;) of
the CDATA section are the responsibility of the calling method.

@param str
The String that is inserted into an existing CDATA Section.