Log4JModel { public ImmutableList<Appender> getAppenders() { if (appenders == null) { final Map<String, String> appenderEntries = filterKeys(log4jProperties, containsPattern("^log4j\\.appender\\.[^\\.]+\\s*$")); appenders = FluentIterable.from(appenderEntries.entrySet()) .transform(appenderFunction(log4jProperties)) .toList(); } return appenders; } Log4JModel(Properties log4jProperties); ImmutableList<Appender> getAppenders(); ImmutableList<Logger> getLoggers(); Root getRootLogger();  }
@Test public void shouldExtractSingleSimpleAppender() { Properties props = new Properties(); props.setProperty("log4j.appender.foo", "com.fragstealers.Test"); Log4JModel model = new Log4JModel(props); List<Appender> appenders = model.getAppenders(); assertThat(appenders.size(), is(1)); Appender appender = appenders.get(0); assertThat(appender.getName(), is("foo")); assertThat(appender.getClazz(), is("com.fragstealers.Test")); }
@Test public void shouldExtractSingleAppenderWithParams() { Properties props = new Properties(); props.setProperty("log4j.appender.foo", "com.fragstealers.Test"); props.setProperty("log4j.appender.foo.1", "x"); props.setProperty("log4j.appender.foo.2", "y"); props.setProperty("log4j.appender.foo.3", "z.a"); Log4JModel model = new Log4JModel(props); List<Appender> appenders = model.getAppenders(); assertThat(appenders.size(), is(1)); Appender appender = appenders.get(0); assertThat(appender.getName(), is("foo")); assertThat(appender.getClazz(), is("com.fragstealers.Test")); final List<Param> param = appender.getParam(); assertThat(param.size(), is(3)); assertThat(param.get(0).getName(), is("1")); assertThat(param.get(0).getValue(), is("x")); assertThat(param.get(1).getName(), is("2")); assertThat(param.get(1).getValue(), is("y")); assertThat(param.get(2).getName(), is("3")); assertThat(param.get(2).getValue(), is("z.a")); }
@Test public void shouldExtractSingleAppenderWithSimpleLayout() { Properties props = new Properties(); props.setProperty("log4j.appender.foo", "com.fragstealers.Test"); props.setProperty("log4j.appender.foo.layout", "com.fragstealers.Layout"); Log4JModel model = new Log4JModel(props); List<Appender> appenders = model.getAppenders(); assertThat(appenders.size(), is(1)); Appender appender = appenders.get(0); assertThat(appender.getName(), is("foo")); assertThat(appender.getClazz(), is("com.fragstealers.Test")); final List<Param> param = appender.getParam(); assertThat(param.size(), is(0)); Layout layout = appender.getLayout(); assertThat(layout.getClazz(), is("com.fragstealers.Layout")); }
@Test public void shouldExtractSingleAppenderWithComplexLayout() { Properties props = new Properties(); props.setProperty("log4j.appender.foo", "com.fragstealers.Test"); props.setProperty("log4j.appender.foo.layout", "com.fragstealers.Layout"); props.setProperty("log4j.appender.foo.layout.1", "x"); props.setProperty("log4j.appender.foo.layout.2", "y"); Log4JModel model = new Log4JModel(props); List<Appender> appenders = model.getAppenders(); assertThat(appenders.size(), is(1)); Appender appender = appenders.get(0); assertThat(appender.getName(), is("foo")); assertThat(appender.getClazz(), is("com.fragstealers.Test")); assertThat(appender.getParam(), Matchers.empty()); Layout layout = appender.getLayout(); assertThat(layout.getClazz(), is("com.fragstealers.Layout")); List<Param> layoutParam = layout.getParam(); assertThat(layoutParam, hasSize(2)); assertThat(layoutParam.get(0).getName(), is("1")); assertThat(layoutParam.get(0).getValue(), is("x")); assertThat(layoutParam.get(1).getName(), is("2")); assertThat(layoutParam.get(1).getValue(), is("y")); }