Skip to content

Commit 3c900f7

Browse files
Merge pull request #190 from vpavic/tweak-logging
Improve logging
2 parents 119ba98 + 41aaf19 commit 3c900f7

File tree

6 files changed

+19
-27
lines changed

6 files changed

+19
-27
lines changed

src/main/java/com/amazon/sqs/javamessaging/SQSMessageConsumer.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ void doClose() {
224224

225225
try {
226226
if (!prefetchExecutor.isShutdown()) {
227-
LOG.info("Shutting down " + SQSSession.CONSUMER_PREFETCH_EXECUTOR_NAME + " executor");
227+
LOG.debug("Shutting down {} executor", SQSSession.CONSUMER_PREFETCH_EXECUTOR_NAME);
228228
// Shut down executor.
229229
prefetchExecutor.shutdown();
230230
}
@@ -233,9 +233,8 @@ void doClose() {
233233

234234
if (!prefetchExecutor.awaitTermination(PREFETCH_EXECUTOR_GRACEFUL_SHUTDOWN_TIME, TimeUnit.SECONDS)) {
235235

236-
LOG.warn("Can't terminate executor service " + SQSSession.CONSUMER_PREFETCH_EXECUTOR_NAME +
237-
" after " + PREFETCH_EXECUTOR_GRACEFUL_SHUTDOWN_TIME +
238-
" seconds, some running threads will be shutdown immediately");
236+
LOG.warn("Can't terminate executor service {} after {} seconds, some running threads will be shutdown immediately",
237+
SQSSession.CONSUMER_PREFETCH_EXECUTOR_NAME, PREFETCH_EXECUTOR_GRACEFUL_SHUTDOWN_TIME);
239238
prefetchExecutor.shutdownNow();
240239
}
241240
} catch (InterruptedException e) {

src/main/java/com/amazon/sqs/javamessaging/SQSMessageConsumerPrefetch.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,7 @@ protected jakarta.jms.Message convertToJMSMessage(Message message) throws JMSExc
349349
try {
350350
jmsMessage = new SQSBytesMessage(acknowledger, queueUrl, message);
351351
} catch (JMSException e) {
352-
LOG.warn("MessageReceiptHandle - " + message.receiptHandle() +
353-
"cannot be serialized to BytesMessage", e);
352+
LOG.warn("MessageReceiptHandle - {} cannot be serialized to BytesMessage", message.receiptHandle(), e);
354353
throw e;
355354
}
356355
} else if (SQSMessage.OBJECT_MESSAGE_TYPE.equals(messageType)) {

src/main/java/com/amazon/sqs/javamessaging/SQSMessageProducer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright 2010-2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.
@@ -152,7 +152,7 @@ void sendInternal(SQSQueueDestination queue, Message rawMessage) throws JMSExcep
152152

153153
SendMessageResponse sendMessageResult = amazonSQSClient.sendMessage(sendMessageRequest.build());
154154
String messageId = sendMessageResult.messageId();
155-
LOG.info("Message sent to SQS with SQS-assigned messageId: " + messageId);
155+
LOG.debug("Message sent to SQS with SQS-assigned messageId: {}", messageId);
156156
// TODO: Do not support disableMessageID for now.
157157
message.setSQSMessageId(messageId);
158158

src/main/java/com/amazon/sqs/javamessaging/SQSSession.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright 2010-2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.
@@ -405,7 +405,7 @@ void doClose() throws JMSException {
405405

406406
try {
407407
if (executor != null) {
408-
LOG.info("Shutting down " + SESSION_EXECUTOR_NAME + " executor");
408+
LOG.debug("Shutting down {} executor", SESSION_EXECUTOR_NAME);
409409

410410
executor.shutdown();
411411

@@ -419,9 +419,8 @@ void doClose() throws JMSException {
419419

420420
if (!executor.awaitTermination(10, TimeUnit.SECONDS)) {
421421

422-
LOG.warn("Can't terminate executor service " + SESSION_EXECUTOR_NAME + " after " +
423-
SESSION_EXECUTOR_GRACEFUL_SHUTDOWN_TIME +
424-
" seconds, some running threads will be shutdown immediately");
422+
LOG.warn("Can't terminate executor service {} after {} seconds, some running threads will be shutdown immediately",
423+
SESSION_EXECUTOR_NAME, SESSION_EXECUTOR_GRACEFUL_SHUTDOWN_TIME);
425424
executor.shutdownNow();
426425
}
427426
}

src/main/java/com/amazon/sqs/javamessaging/SQSSessionCallbackScheduler.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,7 @@ public void run() {
103103
* Will be retried on the next loop, and
104104
* break if the callback scheduler is closed.
105105
*/
106-
if (LOG.isDebugEnabled()) {
107-
LOG.debug("wait on empty callback queue interrupted: " + e.getMessage());
108-
}
106+
LOG.debug("wait on empty callback queue interrupted: {}", e.getMessage());
109107
}
110108
continue;
111109
}
@@ -124,9 +122,7 @@ public void run() {
124122
// this takes care of start and stop
125123
session.startingCallback(messageConsumer);
126124
} catch (JMSException e) {
127-
if (LOG.isDebugEnabled()) {
128-
LOG.debug("Not running callback: " + e.getMessage());
129-
}
125+
LOG.debug("Not running callback: {}", e.getMessage());
130126
break;
131127
}
132128

@@ -147,8 +143,8 @@ public void run() {
147143
try {
148144
messageListener.onMessage(message);
149145
} catch (Throwable ex) {
150-
LOG.info("Exception thrown from onMessage callback for message " +
151-
message.getSQSMessageId(), ex);
146+
LOG.warn("Exception thrown from onMessage callback for message {}",
147+
message.getSQSMessageId(), ex);
152148
callbackFailed = true;
153149
} finally {
154150
if (!callbackFailed) {
@@ -160,9 +156,8 @@ public void run() {
160156
}
161157
}
162158
} catch (JMSException ex) {
163-
LOG.warn(
164-
"Unable to complete message dispatch for the message " +
165-
message.getSQSMessageId(), ex);
159+
LOG.warn("Unable to complete message dispatch for the message {}",
160+
message.getSQSMessageId(), ex);
166161
} finally {
167162
if (tryNack) {
168163
nackReceivedMessage(message);
@@ -248,7 +243,7 @@ private void nackReceivedMessage(SQSMessage message) {
248243

249244
negativeAcknowledger.bulkAction(nackMessageIdentifiers, nackMessageIdentifiers.size());
250245
} catch (JMSException e) {
251-
LOG.warn("Unable to nack the message " + message.getSQSMessageId(), e);
246+
LOG.warn("Unable to nack the message {}", message.getSQSMessageId(), e);
252247
}
253248
}
254249

src/main/java/com/amazon/sqs/javamessaging/acknowledge/RangedAcknowledger.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ public void acknowledge(SQSMessage message) throws JMSException {
7272
* the messages received before that
7373
*/
7474
if (indexOfMessage == -1) {
75-
LOG.warn("SQSMessageID: " + message.getSQSMessageId() + " with SQSMessageReceiptHandle: " +
76-
message.getReceiptHandle() + " does not exist.");
75+
LOG.warn("SQSMessageID: {} with SQSMessageReceiptHandle: {} does not exist.", message.getSQSMessageId(),
76+
message.getReceiptHandle());
7777
} else {
7878
bulkAction(getUnAckMessages(), indexOfMessage);
7979
}

0 commit comments

Comments
 (0)