Log4JModel { public ImmutableList<Logger> getLoggers() { if (loggers == null) { final Map<String, String> loggerEntries = filterKeys(log4jProperties, startsWith("log4j.logger.")); loggers = FluentIterable.from(loggerEntries.entrySet()) .transform(loggerFunction(log4jProperties, getAppenders())) .toList(); } return loggers; } Log4JModel(Properties log4jProperties); ImmutableList<Appender> getAppenders(); ImmutableList<Logger> getLoggers(); Root getRootLogger();  }
@Test public void shouldExtractBasicLogger() { Properties props = new Properties(); props.setProperty("log4j.logger.foo.bar.baz", "debug"); Log4JModel model = new Log4JModel(props); List<Logger> loggers = model.getLoggers(); assertThat(loggers.size(), is(1)); Logger logger = loggers.get(0); assertThat(logger.getName(), is("foo.bar.baz")); assertThat(logger.getLevel().getValue(), is("DEBUG")); }
@Test public void shouldExtractBasicLoggerWithAppenderRefs() { Properties props = new Properties(); props.setProperty("log4j.logger.foo.bar.baz", "debug , ap1 , ap2"); props.setProperty("log4j.appender.ap1", "foo"); props.setProperty("log4j.appender.ap2", "bar"); Log4JModel model = new Log4JModel(props); List<Logger> loggers = model.getLoggers(); assertThat(loggers.size(), is(1)); Logger logger = loggers.get(0); assertThat(logger.getName(), is("foo.bar.baz")); assertThat(logger.getLevel().getValue(), is("DEBUG")); assertThat(logger.getAppenderRef(), hasSize(2)); assertThat(((Appender) logger.getAppenderRef().get(0).getRef()).getName(), is("ap1")); assertThat(((Appender) logger.getAppenderRef().get(1).getRef()).getName(), is("ap2")); }
@Test public void shouldExtractBasicLoggerWithAdditivity() { Properties props = new Properties(); props.setProperty("log4j.logger.foo.bar.baz", "debug"); props.setProperty("log4j.additivity.foo.bar.baz", "true"); Log4JModel model = new Log4JModel(props); List<Logger> loggers = model.getLoggers(); assertThat(loggers.size(), is(1)); Logger logger = loggers.get(0); assertThat(logger.getName(), is("foo.bar.baz")); assertThat(logger.getLevel().getValue(), is("DEBUG")); assertThat(logger.getAdditivity(), is("true")); }
@Test public void shouldDealWithLoggersNamedAsCategories() { Properties props = new Properties(); props.setProperty("log4j.category.foo.bar.baz", "debug"); Log4JModel model = new Log4JModel(props); List<Logger> loggers = model.getLoggers(); assertThat(loggers.size(), is(1)); Logger logger = loggers.get(0); assertThat(logger.getName(), is("foo.bar.baz")); assertThat(logger.getLevel().getValue(), is("DEBUG")); }