From c6891c51840418c1909b09810376dc54ca9bac2a Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Thu, 14 Oct 2021 16:02:48 -0400 Subject: [PATCH 1/2] Add a config prop to enable/disable SI's default logging See gh-28355 --- .../IntegrationAutoConfiguration.java | 3 ++- .../integration/IntegrationProperties.java | 23 +++++++++++++++++++ .../IntegrationAutoConfigurationTests.java | 9 ++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfiguration.java index 6b6e585151..10ee727e13 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfiguration.java @@ -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 { } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationProperties.java index 24349d0b7a..0330e104ee 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationProperties.java @@ -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,21 @@ public class IntegrationProperties { } + public static class Management { + + /** + * Logging management in the integration components. + */ + boolean defaultLoggingEnabled = true; + + public boolean isDefaultLoggingEnabled() { + return this.defaultLoggingEnabled; + } + + public void setDefaultLoggingEnabled(boolean defaultLoggingEnabled) { + this.defaultLoggingEnabled = defaultLoggingEnabled; + } + + } + } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfigurationTests.java index d90a1cb29c..e54767bdda 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfigurationTests.java @@ -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,14 @@ class IntegrationAutoConfigurationTests { }); } + @Test + void integrationManagementLoggingDisabled() { + 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 { From 657eb86dad5dcab00f5306580516a5a12e2e837e Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 19 Oct 2021 10:28:57 +0100 Subject: [PATCH 2/2] Polish "Add a config prop to enable/disable SI's default logging" See gh-28355 --- .../autoconfigure/integration/IntegrationProperties.java | 7 +++++-- .../integration/IntegrationAutoConfigurationTests.java | 8 +++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationProperties.java index 0330e104ee..54111bf46f 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationProperties.java @@ -395,9 +395,12 @@ public class IntegrationProperties { public static class Management { /** - * Logging management in the integration components. + * 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. */ - boolean defaultLoggingEnabled = true; + private boolean defaultLoggingEnabled = true; public boolean isDefaultLoggingEnabled() { return this.defaultLoggingEnabled; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfigurationTests.java index e54767bdda..4f66bd1645 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfigurationTests.java @@ -486,7 +486,13 @@ class IntegrationAutoConfigurationTests { } @Test - void integrationManagementLoggingDisabled() { + 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));