use of io.dropwizard.configuration.SubstitutingSourceProvider in project dropwizard by dropwizard.
the class HelloWorldApplication method initialize.
@Override
public void initialize(Bootstrap<HelloWorldConfiguration> bootstrap) {
// Enable variable substitution with environment variables
bootstrap.setConfigurationSourceProvider(new SubstitutingSourceProvider(bootstrap.getConfigurationSourceProvider(), new EnvironmentVariableSubstitutor(false)));
bootstrap.addCommand(new RenderCommand());
bootstrap.addBundle(new AssetsBundle());
bootstrap.addBundle(new MigrationsBundle<HelloWorldConfiguration>() {
@Override
public DataSourceFactory getDataSourceFactory(HelloWorldConfiguration configuration) {
return configuration.getDataSourceFactory();
}
});
bootstrap.addBundle(hibernateBundle);
bootstrap.addBundle(new ViewBundle<HelloWorldConfiguration>() {
@Override
public Map<String, Map<String, String>> getViewConfiguration(HelloWorldConfiguration configuration) {
return configuration.getViewRendererConfiguration();
}
});
}
use of io.dropwizard.configuration.SubstitutingSourceProvider in project dropwizard by dropwizard.
the class DefaultLoggingFactoryTest method testConfigure.
@Test
public void testConfigure() throws Exception {
final File newAppLog = folder.newFile("example-new-app.log");
final File newAppNotAdditiveLog = folder.newFile("example-new-app-not-additive.log");
final File defaultLog = folder.newFile("example.log");
final StrSubstitutor substitutor = new StrSubstitutor(ImmutableMap.of("new_app", StringUtils.removeEnd(newAppLog.getAbsolutePath(), ".log"), "new_app_not_additive", StringUtils.removeEnd(newAppNotAdditiveLog.getAbsolutePath(), ".log"), "default", StringUtils.removeEnd(defaultLog.getAbsolutePath(), ".log")));
final String configPath = Resources.getResource("yaml/logging_advanced.yml").getFile();
final DefaultLoggingFactory config = factory.build(new SubstitutingSourceProvider(new FileConfigurationSourceProvider(), substitutor), configPath);
config.configure(new MetricRegistry(), "test-logger");
LoggerFactory.getLogger("com.example.app").debug("Application debug log");
LoggerFactory.getLogger("com.example.app").info("Application log");
LoggerFactory.getLogger("com.example.newApp").debug("New application debug log");
LoggerFactory.getLogger("com.example.newApp").info("New application info log");
LoggerFactory.getLogger("com.example.legacyApp").debug("Legacy application debug log");
LoggerFactory.getLogger("com.example.legacyApp").info("Legacy application info log");
LoggerFactory.getLogger("com.example.notAdditive").debug("Not additive application debug log");
LoggerFactory.getLogger("com.example.notAdditive").info("Not additive application info log");
config.stop();
assertThat(Files.readLines(defaultLog, StandardCharsets.UTF_8)).containsOnly("INFO com.example.app: Application log", "DEBUG com.example.newApp: New application debug log", "INFO com.example.newApp: New application info log", "DEBUG com.example.legacyApp: Legacy application debug log", "INFO com.example.legacyApp: Legacy application info log");
assertThat(Files.readLines(newAppLog, StandardCharsets.UTF_8)).containsOnly("DEBUG com.example.newApp: New application debug log", "INFO com.example.newApp: New application info log");
assertThat(Files.readLines(newAppNotAdditiveLog, StandardCharsets.UTF_8)).containsOnly("DEBUG com.example.notAdditive: Not additive application debug log", "INFO com.example.notAdditive: Not additive application info log");
}
Aggregations