From f9f66015fda91bfa489b7c537b57c424a42b86ca Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Mon, 16 Dec 2024 11:00:09 -0500 Subject: [PATCH] log exception along the message --- .../inbound/PubSubInboundChannelAdapter.java | 10 ++-------- .../inbound/PubSubInboundChannelAdapterTests.java | 6 ++++-- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/spring-cloud-gcp-pubsub/src/main/java/com/google/cloud/spring/pubsub/integration/inbound/PubSubInboundChannelAdapter.java b/spring-cloud-gcp-pubsub/src/main/java/com/google/cloud/spring/pubsub/integration/inbound/PubSubInboundChannelAdapter.java index 4ae2374056..21bb4990fb 100644 --- a/spring-cloud-gcp-pubsub/src/main/java/com/google/cloud/spring/pubsub/integration/inbound/PubSubInboundChannelAdapter.java +++ b/spring-cloud-gcp-pubsub/src/main/java/com/google/cloud/spring/pubsub/integration/inbound/PubSubInboundChannelAdapter.java @@ -24,8 +24,6 @@ import com.google.cloud.spring.pubsub.support.GcpPubSubHeaders; import com.google.cloud.spring.pubsub.support.converter.ConvertedBasicAcknowledgeablePubsubMessage; import com.google.pubsub.v1.ProjectSubscriptionName; -import java.io.PrintWriter; -import java.io.StringWriter; import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -177,14 +175,10 @@ private void logWarning( // so we explicitly log failure messages. // See https://github.com/spring-projects/spring-framework/issues/25162 for more info. if (re instanceof MessageDeliveryException messageDeliveryException) { - LOGGER.warn(messageDeliveryException.getFailedMessage()); + LOGGER.warn(messageDeliveryException.getFailedMessage(), messageDeliveryException); } else { - LOGGER.warn(re.getMessage()); + LOGGER.warn(re.getMessage(), re); } - // Log the stacktrace for troubleshoot. - StringWriter stringWriter = new StringWriter(); - re.printStackTrace(new PrintWriter(stringWriter)); - LOGGER.warn(stringWriter.toString()); } private void addToHealthRegistry() { diff --git a/spring-cloud-gcp-pubsub/src/test/java/com/google/cloud/spring/pubsub/integration/inbound/PubSubInboundChannelAdapterTests.java b/spring-cloud-gcp-pubsub/src/test/java/com/google/cloud/spring/pubsub/integration/inbound/PubSubInboundChannelAdapterTests.java index b61f42cd2f..925fc53ded 100644 --- a/spring-cloud-gcp-pubsub/src/test/java/com/google/cloud/spring/pubsub/integration/inbound/PubSubInboundChannelAdapterTests.java +++ b/spring-cloud-gcp-pubsub/src/test/java/com/google/cloud/spring/pubsub/integration/inbound/PubSubInboundChannelAdapterTests.java @@ -166,8 +166,10 @@ void testAckModeAuto_nacksWhenDownstreamProcessingFailsWhenContextShutdown(Captu verify(mockAcknowledgeableMessage, times(0)).ack(); // original message handling exception - assertThat(capturedOutput).contains("failed; message nacked automatically").contains(EXCEPTION_MESSAGE); - assertThat(capturedOutput).contains("Caused by"); + assertThat(capturedOutput) + .contains("failed; message nacked automatically") + .contains(EXCEPTION_MESSAGE) + .contains("Caused by"); } @Test