Merge pull request #32184 from ldziedziul

* pr/32184:
  Polish "Make sure Hazelcast shutdown logs are available"
  Make sure Hazelcast shutdown logs are available

Closes gh-32184
pull/32861/head
Stephane Nicoll 2 years ago
commit 74a88cd34a

@ -52,6 +52,8 @@ class HazelcastServerConfiguration {
static final String CONFIG_SYSTEM_PROPERTY = "hazelcast.config"; static final String CONFIG_SYSTEM_PROPERTY = "hazelcast.config";
static final String HAZELCAST_LOGGING_TYPE = "hazelcast.logging.type";
private static HazelcastInstance getHazelcastInstance(Config config) { private static HazelcastInstance getHazelcastInstance(Config config) {
if (StringUtils.hasText(config.getInstanceName())) { if (StringUtils.hasText(config.getInstanceName())) {
return Hazelcast.getOrCreateHazelcastInstance(config); return Hazelcast.getOrCreateHazelcastInstance(config);
@ -123,6 +125,22 @@ class HazelcastServerConfiguration {
} }
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(org.slf4j.Logger.class)
static class HazelcastLoggingConfigCustomizerConfiguration {
@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 * {@link HazelcastConfigResourceCondition} that checks if the
* {@code spring.hazelcast.config} configuration key is defined. * {@code spring.hazelcast.config} configuration key is defined.

@ -206,6 +206,22 @@ class HazelcastAutoConfigurationServerTests {
}); });
} }
@Test
void autoConfiguredConfigSetsHazelcastLoggingToSlf4j() {
this.contextRunner.run((context) -> {
Config config = context.getBean(HazelcastInstance.class).getConfig();
assertThat(config.getProperty(HazelcastServerConfiguration.HAZELCAST_LOGGING_TYPE)).isEqualTo("slf4j");
});
}
@Test
void autoConfiguredConfigCanOverrideHazelcastLogging() {
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) { private static Config createTestConfig(String instanceName) {
Config config = new Config(instanceName); Config config = new Config(instanceName);
JoinConfig join = config.getNetworkConfig().getJoin(); JoinConfig join = config.getNetworkConfig().getJoin();
@ -236,6 +252,18 @@ class HazelcastAutoConfigurationServerTests {
} }
@Configuration(proxyBeanMethods = false)
static class HazelcastConfigWithJDKLogging {
@Bean
Config anotherHazelcastConfig() {
Config config = new Config();
config.setProperty(HazelcastServerConfiguration.HAZELCAST_LOGGING_TYPE, "jdk");
return config;
}
}
@SpringAware @SpringAware
static class SpringAwareEntryProcessor<V> implements EntryProcessor<String, V, String> { static class SpringAwareEntryProcessor<V> implements EntryProcessor<String, V, String> {

Loading…
Cancel
Save