AndroidLogcatFormatter extends DefaultLogFormatter { @NotNull public String formatMessage(@NotNull String format, @NotNull LogCatHeader header, @NotNull String message) { if (header.getTimestamp() == null) { return myLongEpochFormatter.format(format, header, message); } if (header.getTimestampInstant() == null) { return myLongFormatter.format(format, header, message); } throw new AssertionError(header); } AndroidLogcatFormatter(@NotNull ZoneId timeZone, @NotNull AndroidLogcatPreferences preferences); @NotNull static String formatContinuation(@NotNull String message); @NotNull static String createCustomFormat(boolean showTime, boolean showPid, boolean showPackage, boolean showTag); @NotNull String formatMessage(@NotNull String format, @NotNull LogCatHeader header, @NotNull String message); @Nullable static String tryParseContinuation(@NotNull String msg); @Override String formatPrefix(String prefix); @NotNull @Override String formatMessage(@NotNull String message); static final CharSequence CONTINUATION_INDENT; }
@Test public void unknownFormatMessageRemainsSame() { String message = "some message that doesn't match any known AndroidLogcatFormatter format"; String formattedMessage = myFormatter.formatMessage(message); assertEquals(message, formattedMessage); }
@Test public void emptyFormatMessageLeavesTheSame() { String message = "01-23 12:34:56.789 1234-56/com.dummy.test D/test: Test message"; assertEquals("", myPreferences.LOGCAT_FORMAT_STRING); String formattedMessage = myFormatter.formatMessage(message); assertEquals(message, formattedMessage); }
@Test public void formatMessageIndentsContinuationIndentLengthSpaces() { myFormatter.formatMessage( "2018-12-18 14:13:55.926 1620-1640/system_process V/StorageManagerService: Found primary storage at VolumeInfo{emulated}:"); assertEquals( " type=EMULATED diskId=null partGuid=null mountFlags=0 mountUserId=-1 ", myFormatter.formatMessage("+ type=EMULATED diskId=null partGuid=null mountFlags=0 mountUserId=-1 ")); }