@Test public void truncateLongLines() throws Exception { for (int i = 0; i < 20; i++) { String s = ""; 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); 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) + " ...")); } } } }
public static String truncateMessageLineLength(Object message) { return truncateMessageLineLength(message, MAX_TRUNCATED_LENGTH); }
LogUtils { public static String truncateMessageLineLength(Object message) { return truncateMessageLineLength(message, MAX_TRUNCATED_LENGTH); } }
LogUtils { public static String truncateMessageLineLength(Object message) { return truncateMessageLineLength(message, MAX_TRUNCATED_LENGTH); } private  LogUtils(); }
LogUtils { public static String truncateMessageLineLength(Object message) { return truncateMessageLineLength(message, MAX_TRUNCATED_LENGTH); } private  LogUtils(); static LogInfo setLogLevel(String logName, String level); static void warnWithException(Logger logger, String message, Object ...args); static String truncateMessageLineLength(Object message); static String truncateMessageLineLength(Object message, int maxLineLength); }
LogUtils { public static String truncateMessageLineLength(Object message) { return truncateMessageLineLength(message, MAX_TRUNCATED_LENGTH); } private  LogUtils(); static LogInfo setLogLevel(String logName, String level); static void warnWithException(Logger logger, String message, Object ...args); static String truncateMessageLineLength(Object message); static String truncateMessageLineLength(Object message, int maxLineLength); static final int MAX_TRUNCATED_LENGTH; }