PatternFlattener implements Flattener, Flattener2 { static DateFiller parseDateParameter(String wrappedParameter, String trimmedParameter) { if (trimmedParameter.startsWith(PARAMETER_DATE + " ") && trimmedParameter.length() > PARAMETER_DATE.length() + 1) { String dateFormat = trimmedParameter.substring(PARAMETER_DATE.length() + 1); return new DateFiller(wrappedParameter, trimmedParameter, dateFormat); } else if (trimmedParameter.equals(PARAMETER_DATE)) { return new DateFiller(wrappedParameter, trimmedParameter, DEFAULT_DATE_FORMAT); } return null; } PatternFlattener(String pattern); @Override CharSequence flatten(int logLevel, String tag, String message); @Override CharSequence flatten(long timeMillis, int logLevel, String tag, String message);  }
@Test public void testParseDateParameter() { PatternFlattener.ParameterFiller parameterFiller = PatternFlattener.parseDateParameter( "{d yyyy}", "d yyyy"); assertNoNullAndClass(parameterFiller, PatternFlattener.DateFiller.class); assertEquals("yyyy", ((PatternFlattener.DateFiller) parameterFiller).dateFormat); parameterFiller = PatternFlattener.parseDateParameter("{d}", "d"); assertNoNullAndClass(parameterFiller, PatternFlattener.DateFiller.class); assertEquals(PatternFlattener.DEFAULT_DATE_FORMAT, ((PatternFlattener.DateFiller) parameterFiller).dateFormat); parameterFiller = PatternFlattener.parseDateParameter("{D}", "D"); assertNull(parameterFiller); }