public static String truncateMessageLineLength(Object message) {
    return truncateMessageLineLength(message, MAX_TRUNCATED_LENGTH);
  }
@Test
  public void truncateLongLines() throws Exception {
    for (int i = 0; i < 20; i++) {
      String s = "";
      // generate lines both short and long
      int lines = ThreadLocalRandom.current().nextInt(5, 10);
      for (int j = 0; j < lines; j++) {
        s += "\n";
        if (j % 2 == 0) {
          s += CommonUtils.randomAlphaNumString(
              ThreadLocalRandom.current().nextInt(1, LogUtils.MAX_TRUNCATED_LENGTH + 1));
        } else {
          s = CommonUtils.randomAlphaNumString(ThreadLocalRandom.current()
              .nextInt(LogUtils.MAX_TRUNCATED_LENGTH + 1, 2 + LogUtils.MAX_TRUNCATED_LENGTH));
        }
      }

      String truncated = LogUtils.truncateMessageLineLength(s);

      String[] expectedLines = s.split("\n");
      String[] actualLines = truncated.split("\n");
      assertEquals(expectedLines.length, actualLines.length);

      // check each line
      for (int j = 0; j < expectedLines.length; j++) {
        if (expectedLines[j].length() <= LogUtils.MAX_TRUNCATED_LENGTH) {
          assertEquals(expectedLines[j], actualLines[j]);
        } else {
          assertTrue(actualLines[j]
              .startsWith(expectedLines[j].substring(0, LogUtils.MAX_TRUNCATED_LENGTH) + " ..."));
        }
      }
    }
  }