PatternFlattener implements Flattener, Flattener2 { static List<String> parsePattern(String pattern) { List<String> parameters = new ArrayList<>(4); Matcher matcher = PARAM_REGEX.matcher(pattern); while (matcher.find()) { parameters.add(matcher.group(1)); } return parameters; } 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 testParsePattern() { List<String> parameters = PatternFlattener.parsePattern( "{d yyyy-MM-dd hh:mm:ss.SSS} {l}/{t}: {m}"); assertNotNull(parameters); assertEquals(4, parameters.size()); assertEquals("d yyyy-MM-dd hh:mm:ss.SSS", parameters.get(0)); assertEquals("l", parameters.get(1)); assertEquals("t", parameters.get(2)); assertEquals("m", parameters.get(3)); parameters = PatternFlattener.parsePattern( "Abc { d yyyy } {l }/{ t}: { m } def"); assertNotNull(parameters); assertEquals(4, parameters.size()); assertEquals(" d yyyy ", parameters.get(0)); assertEquals("l ", parameters.get(1)); assertEquals(" t", parameters.get(2)); assertEquals(" m ", parameters.get(3)); parameters = PatternFlattener.parsePattern( "No valid parameter {f }"); assertNotNull(parameters); assertEquals(1, parameters.size()); assertEquals("f ", parameters.get(0)); parameters = PatternFlattener.parsePattern( "No parameter"); assertNotNull(parameters); assertEquals(0, parameters.size()); }