Skip to content

Commit 0702751

Browse files
committed
spring-projectsGH-3555: Change logger order for errorChannel
Fixes spring-projects#3555 The default global `errorChannel` has a `LoggingHandler` as a subscriber. It is subscribed without any `order` which may lose logging messages, when another subscriber with re-throw is present. * Set default `LoggingHandler` on the default `errorChannel` to `Ordered.LOWEST_PRECEDENCE - 100` to give a room for custom subscribers without an `order` and still get error logged
1 parent 60ba544 commit 0702751

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

spring-integration-core/src/main/java/org/springframework/integration/config/DefaultConfiguringBeanFactoryPostProcessor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@
3636
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
3737
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
3838
import org.springframework.beans.factory.support.RootBeanDefinition;
39+
import org.springframework.core.Ordered;
3940
import org.springframework.core.log.LogAccessor;
4041
import org.springframework.integration.channel.ChannelUtils;
4142
import org.springframework.integration.channel.DefaultHeaderChannelRegistry;
4243
import org.springframework.integration.channel.MessagePublishingErrorHandler;
4344
import org.springframework.integration.channel.NullChannel;
4445
import org.springframework.integration.channel.PublishSubscribeChannel;
46+
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
4547
import org.springframework.integration.context.IntegrationContextUtils;
4648
import org.springframework.integration.context.IntegrationProperties;
4749
import org.springframework.integration.handler.LoggingHandler;
@@ -221,6 +223,7 @@ private void registerErrorChannel() {
221223
BeanDefinitionBuilder.genericBeanDefinition(LoggingHandler.class,
222224
() -> new LoggingHandler(LoggingHandler.Level.ERROR))
223225
.addConstructorArgValue(LoggingHandler.Level.ERROR)
226+
.addPropertyValue(IntegrationNamespaceUtils.ORDER, Ordered.LOWEST_PRECEDENCE - 100)
224227
.getBeanDefinition());
225228

226229
BeanDefinitionBuilder loggingEndpointBuilder =

spring-integration-core/src/test/java/org/springframework/integration/config/xml/ErrorChannelAutoCreationTests.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,17 @@
1616

1717
package org.springframework.integration.config.xml;
1818

19+
import java.util.Set;
20+
1921
import org.junit.jupiter.api.Test;
2022

2123
import org.springframework.beans.factory.annotation.Autowired;
24+
import org.springframework.core.Ordered;
2225
import org.springframework.integration.channel.PublishSubscribeChannel;
26+
import org.springframework.integration.handler.LoggingHandler;
2327
import org.springframework.integration.test.util.TestUtils;
2428
import org.springframework.messaging.MessageChannel;
29+
import org.springframework.messaging.MessageHandler;
2530
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
2631

2732
import static org.assertj.core.api.Assertions.assertThat;
@@ -43,6 +48,15 @@ public void testErrorChannelIsPubSub() {
4348
.isTrue();
4449
assertThat(TestUtils.getPropertyValue(this.errorChannel, "dispatcher.ignoreFailures", Boolean.class))
4550
.isTrue();
51+
52+
@SuppressWarnings("unchecked")
53+
Set<MessageHandler> handlers =
54+
TestUtils.getPropertyValue(this.errorChannel, "dispatcher.handlers", Set.class);
55+
56+
assertThat(handlers).first()
57+
.isInstanceOf(LoggingHandler.class)
58+
.extracting("order")
59+
.isEqualTo(Ordered.LOWEST_PRECEDENCE - 100);
4660
}
4761

4862
}

src/reference/asciidoc/error-handling.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ QueueChannel errorChannel() {
5252
====
5353

5454
NOTE: The default error channel is a `PublishSubscribeChannel`.
55+
By default, it has a `LoggingHandler` as a subscriber with an `ERROR` logging level and subscription order as `Ordered.LOWEST_PRECEDENCE - 100`.
5556

5657
The most important thing to understand here is that the messaging-based error handling applies only to exceptions that are thrown by a Spring Integration task that is executing within a `TaskExecutor`.
5758
This does not apply to exceptions thrown by a handler that operates within the same thread as the sender (for example, through a `DirectChannel` as described earlier in this section).

0 commit comments

Comments
 (0)