use of io.dropwizard.configuration.FileConfigurationSourceProvider in project api-core by ca-cwds.
the class ElasticSearchLiveTestRunner method main.
/**
* Let 'er rip!
*
* @param args command line
* @throws Exception Exception rises to the top
*/
public static void main(String... args) throws Exception {
if (args.length < 2) {
throw new ApiException("Usage: java " + ElasticSearchLiveTestRunner.class.getName() + " <ES config file> <search terms>");
}
final String path = args[0];
final String searchFor = args[1];
final ConfigurationSourceProvider provider = new SubstitutingSourceProvider(new FileConfigurationSourceProvider(), new EnvironmentVariableSubstitutor(false));
ElasticsearchConfiguration config;
try (InputStream iss = provider.open(path)) {
config = YAML_MAPPER.readValue(iss, ElasticsearchConfiguration.class);
}
try (AutoCloseElasticsearchDao autoCloseDao = new AutoCloseElasticsearchDao(elasticsearchClient(config))) {
ElasticSearchLiveTestRunner job = new ElasticSearchLiveTestRunner(autoCloseDao, searchFor);
job.run();
}
}
use of io.dropwizard.configuration.FileConfigurationSourceProvider 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