Skip to content

Commit 2e6b0bb

Browse files
committed
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
2 parents 14fb9c4 + 657eb86 commit 2e6b0bb

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfiguration.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ public IntegrationMBeanExporter integrationMbeanExporter(BeanFactory beanFactory
209209
protected static class IntegrationManagementConfiguration {
210210

211211
@Configuration(proxyBeanMethods = false)
212-
@EnableIntegrationManagement
212+
@EnableIntegrationManagement(
213+
defaultLoggingEnabled = "${spring.integration.management.default-logging-enabled:true}")
213214
protected static class EnableIntegrationManagementConfiguration {
214215

215216
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationProperties.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public class IntegrationProperties {
4747

4848
private final Poller poller = new Poller();
4949

50+
private final Management management = new Management();
51+
5052
public Channel getChannel() {
5153
return this.channel;
5254
}
@@ -71,6 +73,10 @@ public Poller getPoller() {
7173
return this.poller;
7274
}
7375

76+
public Management getManagement() {
77+
return this.management;
78+
}
79+
7480
public static class Channel {
7581

7682
/**
@@ -386,4 +392,24 @@ public void setCron(String cron) {
386392

387393
}
388394

395+
public static class Management {
396+
397+
/**
398+
* Whether Spring Integration components should perform logging in the main
399+
* message flow. When disabled, such logging will be skipped without checking the
400+
* logging level. When enabled, such logging is controlled as normal by the
401+
* logging system's log level configuration.
402+
*/
403+
private boolean defaultLoggingEnabled = true;
404+
405+
public boolean isDefaultLoggingEnabled() {
406+
return this.defaultLoggingEnabled;
407+
}
408+
409+
public void setDefaultLoggingEnabled(boolean defaultLoggingEnabled) {
410+
this.defaultLoggingEnabled = defaultLoggingEnabled;
411+
}
412+
413+
}
414+
389415
}

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfigurationTests.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import org.springframework.integration.annotation.IntegrationComponentScan;
5555
import org.springframework.integration.annotation.MessagingGateway;
5656
import org.springframework.integration.annotation.ServiceActivator;
57+
import org.springframework.integration.channel.DirectChannel;
5758
import org.springframework.integration.channel.QueueChannel;
5859
import org.springframework.integration.config.IntegrationManagementConfigurer;
5960
import org.springframework.integration.context.IntegrationContextUtils;
@@ -484,6 +485,20 @@ void whenFixedRatePollerPropertyIsSetThenItIsReflectedAsFixedRatePropertyOfPerio
484485
});
485486
}
486487

488+
@Test
489+
void integrationManagementLoggingIsEnabledByDefault() {
490+
this.contextRunner.withBean(DirectChannel.class, DirectChannel::new).run((context) -> assertThat(context)
491+
.getBean(DirectChannel.class).extracting(DirectChannel::isLoggingEnabled).isEqualTo(true));
492+
}
493+
494+
@Test
495+
void integrationManagementLoggingCanBeDisabled() {
496+
this.contextRunner.withPropertyValues("spring.integration.management.defaultLoggingEnabled=false")
497+
.withBean(DirectChannel.class, DirectChannel::new).run((context) -> assertThat(context)
498+
.getBean(DirectChannel.class).extracting(DirectChannel::isLoggingEnabled).isEqualTo(false));
499+
500+
}
501+
487502
@Configuration(proxyBeanMethods = false)
488503
static class CustomMBeanExporter {
489504

0 commit comments

Comments
 (0)