From a15088cbd33d665a457472e0f513507dc89d8a8d Mon Sep 17 00:00:00 2001 From: cnScarb Date: Tue, 7 May 2024 09:49:43 +0800 Subject: [PATCH] [ISSUE #8096] fix log placeholder --- .../rocketmq/client/impl/ClientRemotingProcessor.java | 4 ++-- .../org/apache/rocketmq/client/impl/MQClientAPIImpl.java | 4 ++-- .../impl/consumer/ConsumeMessageConcurrentlyService.java | 8 ++++---- .../impl/consumer/ConsumeMessageOrderlyService.java | 8 ++++---- .../consumer/ConsumeMessagePopConcurrentlyService.java | 4 ++-- .../impl/consumer/ConsumeMessagePopOrderlyService.java | 4 ++-- .../client/impl/producer/DefaultMQProducerImpl.java | 8 ++++---- .../org/apache/rocketmq/common/stats/MomentStatsItem.java | 4 ++-- .../rocketmq/controller/impl/DLedgerController.java | 2 +- .../apache/rocketmq/test/client/rmq/RMQPopConsumer.java | 2 +- .../org/apache/rocketmq/test/util/MQAdminTestUtils.java | 3 +-- .../test/java/org/apache/rocketmq/test/base/BaseConf.java | 3 +-- .../rocketmq/test/client/consumer/pop/PopSubCheckIT.java | 2 +- 13 files changed, 27 insertions(+), 29 deletions(-) diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/ClientRemotingProcessor.java b/client/src/main/java/org/apache/rocketmq/client/impl/ClientRemotingProcessor.java index 2f18c610c14..e46c651f928 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/ClientRemotingProcessor.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/ClientRemotingProcessor.java @@ -288,8 +288,8 @@ private void processReplyMessage(MessageExt replyMsg) { } } else { String bornHost = replyMsg.getBornHostString(); - logger.warn(String.format("receive reply message, but not matched any request, CorrelationId: %s , reply from host: %s", - correlationId, bornHost)); + logger.warn("receive reply message, but not matched any request, CorrelationId: {} , reply from host: {}", + correlationId, bornHost); } } } diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/MQClientAPIImpl.java b/client/src/main/java/org/apache/rocketmq/client/impl/MQClientAPIImpl.java index 0c58affa34a..9b15279cb62 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/MQClientAPIImpl.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/MQClientAPIImpl.java @@ -1168,7 +1168,7 @@ private PopResult processPopResponse(final String brokerName, final RemotingComm index = sortMap.get(queueIdKey).indexOf(offset); msgQueueOffset = msgOffsetInfo.get(queueIdKey).get(index); if (msgQueueOffset != offset) { - log.warn("Queue offset[%d] of msg is strange, not equal to the stored in msg, %s", + log.warn("Queue offset[{}] of msg is strange, not equal to the stored in msg, {}", msgQueueOffset, messageExt); } messageExt.getProperties().put(MessageConst.PROPERTY_POP_CK, @@ -1181,7 +1181,7 @@ private PopResult processPopResponse(final String brokerName, final RemotingComm index = sortMap.get(queueIdKey).indexOf(messageExt.getQueueOffset()); msgQueueOffset = msgOffsetInfo.get(queueIdKey).get(index); if (msgQueueOffset != messageExt.getQueueOffset()) { - log.warn("Queue offset[%d] of msg is strange, not equal to the stored in msg, %s", msgQueueOffset, messageExt); + log.warn("Queue offset[{}] of msg is strange, not equal to the stored in msg, {}", msgQueueOffset, messageExt); } messageExt.getProperties().put(MessageConst.PROPERTY_POP_CK, ExtraInfoUtil.buildExtraInfo(startOffsetInfo.get(queueIdKey), responseHeader.getPopTime(), responseHeader.getInvisibleTime(), diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/ConsumeMessageConcurrentlyService.java b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/ConsumeMessageConcurrentlyService.java index ea6c8072b57..b151fefbbb3 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/ConsumeMessageConcurrentlyService.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/ConsumeMessageConcurrentlyService.java @@ -169,11 +169,11 @@ public ConsumeMessageDirectlyResult consumeMessageDirectly(MessageExt msg, Strin result.setConsumeResult(CMResult.CR_THROW_EXCEPTION); result.setRemark(UtilAll.exceptionSimpleDesc(e)); - log.warn(String.format("consumeMessageDirectly exception: %s Group: %s Msgs: %s MQ: %s", + log.warn("consumeMessageDirectly exception: {} Group: {} Msgs: {} MQ: {}", UtilAll.exceptionSimpleDesc(e), ConsumeMessageConcurrentlyService.this.consumerGroup, msgs, - mq), e); + mq, e); } result.setSpentTimeMills(System.currentTimeMillis() - beginTime); @@ -410,11 +410,11 @@ public void run() { } status = listener.consumeMessage(Collections.unmodifiableList(msgs), context); } catch (Throwable e) { - log.warn(String.format("consumeMessage exception: %s Group: %s Msgs: %s MQ: %s", + log.warn("consumeMessage exception: {} Group: {} Msgs: {} MQ: {}", UtilAll.exceptionSimpleDesc(e), ConsumeMessageConcurrentlyService.this.consumerGroup, msgs, - messageQueue), e); + messageQueue, e); hasException = true; } long consumeRT = System.currentTimeMillis() - beginTimestamp; diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/ConsumeMessageOrderlyService.java b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/ConsumeMessageOrderlyService.java index cab4fe5d69f..36d686048ce 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/ConsumeMessageOrderlyService.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/ConsumeMessageOrderlyService.java @@ -181,11 +181,11 @@ public ConsumeMessageDirectlyResult consumeMessageDirectly(MessageExt msg, Strin result.setConsumeResult(CMResult.CR_THROW_EXCEPTION); result.setRemark(UtilAll.exceptionSimpleDesc(e)); - log.warn(String.format("consumeMessageDirectly exception: %s Group: %s Msgs: %s MQ: %s", + log.warn("consumeMessageDirectly exception: {} Group: {} Msgs: {} MQ: {}", UtilAll.exceptionSimpleDesc(e), ConsumeMessageOrderlyService.this.consumerGroup, msgs, - mq), e); + mq, e); } result.setAutoCommit(context.isAutoCommit()); @@ -497,11 +497,11 @@ public void run() { status = messageListener.consumeMessage(Collections.unmodifiableList(msgs), context); } catch (Throwable e) { - log.warn(String.format("consumeMessage exception: %s Group: %s Msgs: %s MQ: %s", + log.warn("consumeMessage exception: {} Group: {} Msgs: {} MQ: {}", UtilAll.exceptionSimpleDesc(e), ConsumeMessageOrderlyService.this.consumerGroup, msgs, - messageQueue), e); + messageQueue, e); hasException = true; } finally { this.processQueue.getConsumeLock().readLock().unlock(); diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/ConsumeMessagePopConcurrentlyService.java b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/ConsumeMessagePopConcurrentlyService.java index a61454f5955..3713d1aba4d 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/ConsumeMessagePopConcurrentlyService.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/ConsumeMessagePopConcurrentlyService.java @@ -153,11 +153,11 @@ public ConsumeMessageDirectlyResult consumeMessageDirectly(MessageExt msg, Strin result.setConsumeResult(CMResult.CR_THROW_EXCEPTION); result.setRemark(UtilAll.exceptionSimpleDesc(e)); - log.warn(String.format("consumeMessageDirectly exception: %s Group: %s Msgs: %s MQ: %s", + log.warn("consumeMessageDirectly exception: {} Group: {} Msgs: {} MQ: {}", UtilAll.exceptionSimpleDesc(e), ConsumeMessagePopConcurrentlyService.this.consumerGroup, msgs, - mq), e); + mq, e); } result.setSpentTimeMills(System.currentTimeMillis() - beginTime); diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/ConsumeMessagePopOrderlyService.java b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/ConsumeMessagePopOrderlyService.java index ae6adfea5df..4eab1ccf664 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/ConsumeMessagePopOrderlyService.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/ConsumeMessagePopOrderlyService.java @@ -175,11 +175,11 @@ public ConsumeMessageDirectlyResult consumeMessageDirectly(MessageExt msg, Strin result.setConsumeResult(CMResult.CR_THROW_EXCEPTION); result.setRemark(UtilAll.exceptionSimpleDesc(e)); - log.warn(String.format("consumeMessageDirectly exception: %s Group: %s Msgs: %s MQ: %s", + log.warn("consumeMessageDirectly exception: {} Group: {} Msgs: {} MQ: {}", UtilAll.exceptionSimpleDesc(e), ConsumeMessagePopOrderlyService.this.consumerGroup, msgs, - mq), e); + mq, e); } result.setAutoCommit(context.isAutoCommit()); diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/producer/DefaultMQProducerImpl.java b/client/src/main/java/org/apache/rocketmq/client/impl/producer/DefaultMQProducerImpl.java index d171411d023..5b7bd2dc9dc 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/producer/DefaultMQProducerImpl.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/producer/DefaultMQProducerImpl.java @@ -762,7 +762,7 @@ private SendResult sendDefaultImpl( } catch (MQClientException e) { endTimestamp = System.currentTimeMillis(); this.updateFaultItem(mq.getBrokerName(), endTimestamp - beginTimestampPrev, false, true); - log.warn("sendKernelImpl exception, resend at once, InvokeID: %s, RT: %sms, Broker: %s", invokeID, endTimestamp - beginTimestampPrev, mq, e); + log.warn("sendKernelImpl exception, resend at once, InvokeID: {}, RT: {}ms, Broker: {}", invokeID, endTimestamp - beginTimestampPrev, mq, e); log.warn(msg.toString()); exception = e; continue; @@ -775,7 +775,7 @@ private SendResult sendDefaultImpl( // Otherwise, isolate this broker. this.updateFaultItem(mq.getBrokerName(), endTimestamp - beginTimestampPrev, true, true); } - log.warn("sendKernelImpl exception, resend at once, InvokeID: %s, RT: %sms, Broker: %s", invokeID, endTimestamp - beginTimestampPrev, mq, e); + log.warn("sendKernelImpl exception, resend at once, InvokeID: {}, RT: {}ms, Broker: {}", invokeID, endTimestamp - beginTimestampPrev, mq, e); if (log.isDebugEnabled()) { log.debug(msg.toString()); } @@ -784,7 +784,7 @@ private SendResult sendDefaultImpl( } catch (MQBrokerException e) { endTimestamp = System.currentTimeMillis(); this.updateFaultItem(mq.getBrokerName(), endTimestamp - beginTimestampPrev, true, false); - log.warn("sendKernelImpl exception, resend at once, InvokeID: %s, RT: %sms, Broker: %s", invokeID, endTimestamp - beginTimestampPrev, mq, e); + log.warn("sendKernelImpl exception, resend at once, InvokeID: {}, RT: {}ms, Broker: {}", invokeID, endTimestamp - beginTimestampPrev, mq, e); if (log.isDebugEnabled()) { log.debug(msg.toString()); } @@ -801,7 +801,7 @@ private SendResult sendDefaultImpl( } catch (InterruptedException e) { endTimestamp = System.currentTimeMillis(); this.updateFaultItem(mq.getBrokerName(), endTimestamp - beginTimestampPrev, false, true); - log.warn("sendKernelImpl exception, throw exception, InvokeID: %s, RT: %sms, Broker: %s", invokeID, endTimestamp - beginTimestampPrev, mq, e); + log.warn("sendKernelImpl exception, throw exception, InvokeID: {}, RT: {}ms, Broker: {}", invokeID, endTimestamp - beginTimestampPrev, mq, e); if (log.isDebugEnabled()) { log.debug(msg.toString()); } diff --git a/common/src/main/java/org/apache/rocketmq/common/stats/MomentStatsItem.java b/common/src/main/java/org/apache/rocketmq/common/stats/MomentStatsItem.java index d38281bf83a..71c796b283a 100644 --- a/common/src/main/java/org/apache/rocketmq/common/stats/MomentStatsItem.java +++ b/common/src/main/java/org/apache/rocketmq/common/stats/MomentStatsItem.java @@ -55,10 +55,10 @@ public void run() { } public void printAtMinutes() { - log.info(String.format("[%s] [%s] Stats Every 5 Minutes, Value: %d", + log.info("[{}] [{}] Stats Every 5 Minutes, Value: {}", this.statsName, this.statsKey, - this.value.get())); + this.value.get()); } public AtomicLong getValue() { diff --git a/controller/src/main/java/org/apache/rocketmq/controller/impl/DLedgerController.java b/controller/src/main/java/org/apache/rocketmq/controller/impl/DLedgerController.java index a032b7b6211..be487849ce5 100644 --- a/controller/src/main/java/org/apache/rocketmq/controller/impl/DLedgerController.java +++ b/controller/src/main/java/org/apache/rocketmq/controller/impl/DLedgerController.java @@ -569,7 +569,7 @@ public void handle(long term, MemberState.Role role) { break; } tryTimes++; - log.error(String.format("Controller leader append initial log failed, try %d times", tryTimes)); + log.error("Controller leader append initial log failed, try {} times", tryTimes); if (tryTimes % 3 == 0) { log.warn("Controller leader append initial log failed too many times, please wait a while"); } diff --git a/test/src/main/java/org/apache/rocketmq/test/client/rmq/RMQPopConsumer.java b/test/src/main/java/org/apache/rocketmq/test/client/rmq/RMQPopConsumer.java index a7046bca7da..67a781aacc2 100644 --- a/test/src/main/java/org/apache/rocketmq/test/client/rmq/RMQPopConsumer.java +++ b/test/src/main/java/org/apache/rocketmq/test/client/rmq/RMQPopConsumer.java @@ -58,7 +58,7 @@ public RMQPopConsumer(String nsAddr, String topic, String subExpression, @Override public void start() { client = ConsumerFactory.getRMQPopClient(); - log.info(String.format("consumer[%s] started!", consumerGroup)); + log.info("consumer[{}] started!", consumerGroup); } @Override diff --git a/test/src/main/java/org/apache/rocketmq/test/util/MQAdminTestUtils.java b/test/src/main/java/org/apache/rocketmq/test/util/MQAdminTestUtils.java index d3d5de9e271..47a8db3c9a7 100644 --- a/test/src/main/java/org/apache/rocketmq/test/util/MQAdminTestUtils.java +++ b/test/src/main/java/org/apache/rocketmq/test/util/MQAdminTestUtils.java @@ -117,8 +117,7 @@ public static boolean createSub(String nameSrvAddr, String clusterName, String c for (String addr : masterSet) { try { mqAdminExt.createAndUpdateSubscriptionGroupConfig(addr, config); - log.info(String.format("create subscription group %s to %s success.\n", consumerId, - addr)); + log.info("create subscription group {} to {} success.", consumerId, addr); } catch (Exception e) { e.printStackTrace(); Thread.sleep(1000 * 1); diff --git a/test/src/test/java/org/apache/rocketmq/test/base/BaseConf.java b/test/src/test/java/org/apache/rocketmq/test/base/BaseConf.java index d2713919509..b64cda33420 100644 --- a/test/src/test/java/org/apache/rocketmq/test/base/BaseConf.java +++ b/test/src/test/java/org/apache/rocketmq/test/base/BaseConf.java @@ -287,8 +287,7 @@ public static RMQNormalConsumer getConsumer(String nsAddr, String consumerGroup, consumer.setDebug(); } mqClients.add(consumer); - log.info(String.format("consumer[%s] start,topic[%s],subExpression[%s]", consumerGroup, - topic, subExpression)); + log.info("consumer[{}] start,topic[{}],subExpression[{}]", consumerGroup, topic, subExpression); return consumer; } diff --git a/test/src/test/java/org/apache/rocketmq/test/client/consumer/pop/PopSubCheckIT.java b/test/src/test/java/org/apache/rocketmq/test/client/consumer/pop/PopSubCheckIT.java index e2a657f4343..3034876846f 100644 --- a/test/src/test/java/org/apache/rocketmq/test/client/consumer/pop/PopSubCheckIT.java +++ b/test/src/test/java/org/apache/rocketmq/test/client/consumer/pop/PopSubCheckIT.java @@ -64,7 +64,7 @@ public void tearDown() { @Test public void testNormalPopAck() throws Exception { String topic = initTopic(); - log.info(String.format("use topic: %s; group: %s !", topic, group)); + log.info("use topic: {}; group: {} !", topic, group); RMQNormalProducer producer = getProducer(NAMESRV_ADDR, topic); producer.getProducer().setCompressMsgBodyOverHowmuch(Integer.MAX_VALUE);