Skip to content

Commit

Permalink
log exception along the message
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeWang1127 committed Dec 16, 2024
1 parent 0d826d1 commit f9f6601
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f9f6601

Please sign in to comment.