LogbackConfigurator { public static void initConfiguration(NinjaProperties ninjaProperties) { if (System.getProperty(LOGBACK_CONFIGURATION_FILE_PROPERTY) != null) { return; } String logbackConfigurationFile = ninjaProperties.get(LOGBACK_CONFIGURATION_FILE_PROPERTY); if (logbackConfigurationFile == null) { return; } URL logbackConfigurationFileAsURL = getUrlForStringFromClasspathAsFileOrUrl(logbackConfigurationFile); if (logbackConfigurationFileAsURL == null) { logger.error("Cannot configure logger from {} provided in application.conf", logbackConfigurationFile); return; } LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); try { JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(context); context.reset(); configurator.doConfigure(logbackConfigurationFileAsURL); } catch (JoranException je) { } logger.info("Successfully configured application logging from: {}", logbackConfigurationFileAsURL); StatusPrinter.printInCaseOfErrorsOrWarnings(context); }  static void initConfiguration(NinjaProperties ninjaProperties); final static String LOGBACK_CONFIGURATION_FILE_PROPERTY; }
@Test public void testThatASystemPropertySkipsInitializationFromApplicationConf() { System.setProperty( LogbackConfigurator.LOGBACK_CONFIGURATION_FILE_PROPERTY, "/srv/logback_prod.xml"); LogbackConfigurator.initConfiguration(ninjaProperties); Mockito.verify(ninjaProperties, Mockito.never()).get(Matchers.anyString()); System.clearProperty(LogbackConfigurator.LOGBACK_CONFIGURATION_FILE_PROPERTY); }
@Test public void testThatConfigurationFromApplicationConfWorks() { Mockito.when(ninjaProperties.get( LogbackConfigurator.LOGBACK_CONFIGURATION_FILE_PROPERTY)) .thenReturn("logback_production.xml"); LogbackConfigurator.initConfiguration(ninjaProperties); Mockito.verify(ninjaProperties).get(LogbackConfigurator.LOGBACK_CONFIGURATION_FILE_PROPERTY); }