Skip to content

Commit

Permalink
Make sure Hazelcast shutdown logs are available
Browse files Browse the repository at this point in the history
  • Loading branch information
ldziedziul authored and snicoll committed Sep 7, 2022
1 parent 9ef067d commit 24f3b2b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
Expand Up @@ -51,6 +51,7 @@
class HazelcastServerConfiguration {

static final String CONFIG_SYSTEM_PROPERTY = "hazelcast.config";
static final String HAZELCAST_LOGGING_TYPE = "hazelcast.logging.type";

private static HazelcastInstance getHazelcastInstance(Config config) {
if (StringUtils.hasText(config.getInstanceName())) {
Expand Down Expand Up @@ -123,6 +124,22 @@ HazelcastConfigCustomizer springManagedContextHazelcastConfigCustomizer(Applicat

}

@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(org.slf4j.Logger.class)
static class LoggingHazelcastConfigCustomizerConfiguration {

@Bean
@Order(0)
HazelcastConfigCustomizer loggingHazelcastConfigCustomizer() {
return (config) -> {
if (!config.getProperties().containsKey(HAZELCAST_LOGGING_TYPE)) {
config.setProperty(HAZELCAST_LOGGING_TYPE, "slf4j");
}
};
}

}

/**
* {@link HazelcastConfigResourceCondition} that checks if the
* {@code spring.hazelcast.config} configuration key is defined.
Expand Down
Expand Up @@ -206,6 +206,22 @@ void autoConfiguredContextCanOverrideManagementContextUsingCustomizer() {
});
}

@Test
void configWithDefaultLoggingTypeSlf4j() {
this.contextRunner.run((context) -> {
Config config = context.getBean(HazelcastInstance.class).getConfig();
assertThat(config.getProperty(HazelcastServerConfiguration.HAZELCAST_LOGGING_TYPE)).isEqualTo("slf4j");
});
}

@Test
void configWithExplicitLoggingType() {
this.contextRunner.withUserConfiguration(HazelcastConfigWithJDKLogging.class).run((context) -> {
Config config = context.getBean(HazelcastInstance.class).getConfig();
assertThat(config.getProperty(HazelcastServerConfiguration.HAZELCAST_LOGGING_TYPE)).isEqualTo("jdk");
});
}

private static Config createTestConfig(String instanceName) {
Config config = new Config(instanceName);
JoinConfig join = config.getNetworkConfig().getJoin();
Expand Down Expand Up @@ -236,6 +252,18 @@ Config anotherHazelcastConfig() {

}

@Configuration(proxyBeanMethods = false)
static class HazelcastConfigWithJDKLogging {

@Bean
Config anotherHazelcastConfig() {
Config config = new Config();
config.setProperty(HazelcastServerConfiguration.HAZELCAST_LOGGING_TYPE, "jdk");
return config;
}

}

@SpringAware
static class SpringAwareEntryProcessor<V> implements EntryProcessor<String, V, String> {

Expand Down

0 comments on commit 24f3b2b

Please sign in to comment.