Merge pull request #28355 from artembilan

* gh-28355:
  Polish "Add a config prop to enable/disable SI's default logging"
  Add a config prop to enable/disable SI's default logging

Closes gh-28355
pull/28398/head
Andy Wilkinson 3 years ago
commit 2e6b0bbce1

@ -209,7 +209,8 @@ public class IntegrationAutoConfiguration {
protected static class IntegrationManagementConfiguration {
@Configuration(proxyBeanMethods = false)
@EnableIntegrationManagement
@EnableIntegrationManagement(
defaultLoggingEnabled = "${spring.integration.management.default-logging-enabled:true}")
protected static class EnableIntegrationManagementConfiguration {
}

@ -47,6 +47,8 @@ public class IntegrationProperties {
private final Poller poller = new Poller();
private final Management management = new Management();
public Channel getChannel() {
return this.channel;
}
@ -71,6 +73,10 @@ public class IntegrationProperties {
return this.poller;
}
public Management getManagement() {
return this.management;
}
public static class Channel {
/**
@ -386,4 +392,24 @@ public class IntegrationProperties {
}
public static class Management {
/**
* Whether Spring Integration components should perform logging in the main
* message flow. When disabled, such logging will be skipped without checking the
* logging level. When enabled, such logging is controlled as normal by the
* logging system's log level configuration.
*/
private boolean defaultLoggingEnabled = true;
public boolean isDefaultLoggingEnabled() {
return this.defaultLoggingEnabled;
}
public void setDefaultLoggingEnabled(boolean defaultLoggingEnabled) {
this.defaultLoggingEnabled = defaultLoggingEnabled;
}
}
}

@ -54,6 +54,7 @@ import org.springframework.core.io.ResourceLoader;
import org.springframework.integration.annotation.IntegrationComponentScan;
import org.springframework.integration.annotation.MessagingGateway;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.config.IntegrationManagementConfigurer;
import org.springframework.integration.context.IntegrationContextUtils;
@ -484,6 +485,20 @@ class IntegrationAutoConfigurationTests {
});
}
@Test
void integrationManagementLoggingIsEnabledByDefault() {
this.contextRunner.withBean(DirectChannel.class, DirectChannel::new).run((context) -> assertThat(context)
.getBean(DirectChannel.class).extracting(DirectChannel::isLoggingEnabled).isEqualTo(true));
}
@Test
void integrationManagementLoggingCanBeDisabled() {
this.contextRunner.withPropertyValues("spring.integration.management.defaultLoggingEnabled=false")
.withBean(DirectChannel.class, DirectChannel::new).run((context) -> assertThat(context)
.getBean(DirectChannel.class).extracting(DirectChannel::isLoggingEnabled).isEqualTo(false));
}
@Configuration(proxyBeanMethods = false)
static class CustomMBeanExporter {

Loading…
Cancel
Save