You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by di...@apache.org on 2019/07/30 09:38:53 UTC
[rocketmq-ons-cpp] 26/35: Using log fuction in Logging instead of
spd directly
This is an automated email from the ASF dual-hosted git repository.
dinglei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-ons-cpp.git
commit cfcf52db58066668847722bc2f5664eec56db6d4
Author: ShannonDing <li...@163.com>
AuthorDate: Thu Jul 25 12:28:34 2019 +0800
Using log fuction in Logging instead of spd directly
---
src/main/cpp/sdk/ConsumerImpl.cpp | 10 ++---
src/main/cpp/sdk/OrderConsumerImpl.cpp | 10 ++---
src/main/cpp/sdk/OrderProducerImpl.cpp | 6 +--
src/main/cpp/sdk/ProducerImpl.cpp | 6 +--
src/main/cpp/sdk/TransactionProducerImpl.cpp | 4 +-
src/main/cpp/sdk/common/Logger.h | 60 ++++++++++++++++++++++++++++
src/main/cpp/sdk/common/UtilAll.h | 8 ++--
src/test/cpp/LoggerTest.cpp | 2 +-
8 files changed, 83 insertions(+), 23 deletions(-)
diff --git a/src/main/cpp/sdk/ConsumerImpl.cpp b/src/main/cpp/sdk/ConsumerImpl.cpp
index 286e96d..7164b02 100644
--- a/src/main/cpp/sdk/ConsumerImpl.cpp
+++ b/src/main/cpp/sdk/ConsumerImpl.cpp
@@ -36,7 +36,7 @@ ConsumerImpl::ConsumerImpl(const ons::ONSFactoryProperty &factoryProperty) throw
graal_isolatethread_t *thread_;
ThreadAttachment attachment(&thread_);
this->instanceIndex_ = create_consumer(thread_, &property);
- spdlog::info("Create Consumer OK, InstanceId:{}, ConsumerID:{}, NameServer:{}, Trace:{}, MessageModel:{}",
+ rocketmq::spd_log::info("Create Consumer OK, InstanceId:{}, ConsumerID:{}, NameServer:{}, Trace:{}, MessageModel:{}",
instanceIndex_, factoryProperty.getConsumerId(),
factoryProperty.getNameSrvAddr(), factoryProperty.getOnsTraceSwitch(),
factoryProperty.getMessageModel());
@@ -46,7 +46,7 @@ void ConsumerImpl::start() {
graal_isolatethread_t *thread_;
ThreadAttachment attachment(&thread_);
start_instance(thread_, instanceIndex_);
- spdlog::info("Start Consumer instance {} OK", instanceIndex_);
+ rocketmq::spd_log::info("Start Consumer instance {} OK", instanceIndex_);
}
#ifdef __cplusplus
@@ -67,7 +67,7 @@ int consumer_on_message(void *thread, void *opaque, char *topic, char *user_prop
case CommitMessage:
return 0;
case ReconsumeLater:
- spdlog::info("Consume Message failed, Topic:{}, MessageId:{}, RecosumeTimes:{}",
+ rocketmq::spd_log::info("Consume Message failed, Topic:{}, MessageId:{}, RecosumeTimes:{}",
message_.getTopic(), message_.getMsgID(), message_.getReconsumeTimes());
return 1;
default:
@@ -100,14 +100,14 @@ void ConsumerImpl::subscribe(const char *topic, const char *subExpression, ons::
graal_isolatethread_t *thread_;
ThreadAttachment attachment(&thread_);
::subscribe(thread_, instanceIndex_, &sub);
- spdlog::info("Subscribe OK, InstanceID:{}, Topic:{}, SubExpression:{}", instanceIndex_, topic, subExpression);
+ rocketmq::spd_log::info("Subscribe OK, InstanceID:{}, Topic:{}, SubExpression:{}", instanceIndex_, topic, subExpression);
}
void ConsumerImpl::shutdown() {
graal_isolatethread_t *thread_;
ThreadAttachment attachment(&thread_);
destroy_instance(thread_, instanceIndex_);
- spdlog::info("Destroy Consumer instance {} OK", instanceIndex_);
+ rocketmq::spd_log::info("Destroy Consumer instance {} OK", instanceIndex_);
}
ConsumerImpl::~ConsumerImpl() {
diff --git a/src/main/cpp/sdk/OrderConsumerImpl.cpp b/src/main/cpp/sdk/OrderConsumerImpl.cpp
index 496f263..0b36224 100644
--- a/src/main/cpp/sdk/OrderConsumerImpl.cpp
+++ b/src/main/cpp/sdk/OrderConsumerImpl.cpp
@@ -31,7 +31,7 @@ OrderConsumerImpl::OrderConsumerImpl(const ons::ONSFactoryProperty &factoryPrope
factory_property property;
ons::FactoryPropertyConverter converter(factoryProperty, property, false);
this->instanceIndex_ = create_order_consumer(thread_, &property);
- spdlog::info("Create Order Consumer OK, InstanceId:{}, ConsumerID:{}, NameServer:{}",
+ rocketmq::spd_log::info("Create Order Consumer OK, InstanceId:{}, ConsumerID:{}, NameServer:{}",
instanceIndex_, factoryProperty.getConsumerId(), factoryProperty.getNameSrvAddr());
}
@@ -43,14 +43,14 @@ void OrderConsumerImpl::start() {
graal_isolatethread_t *thread_;
ThreadAttachment attachment(&thread_);
start_instance(thread_, instanceIndex_);
- spdlog::info("Start Order Consumer instance {} OK", instanceIndex_);
+ rocketmq::spd_log::info("Start Order Consumer instance {} OK", instanceIndex_);
}
void OrderConsumerImpl::shutdown() {
graal_isolatethread_t *thread_;
ThreadAttachment attachment(&thread_);
destroy_instance(thread_, instanceIndex_);
- spdlog::info("Destroy Order Consumer instance {} OK", instanceIndex_);
+ rocketmq::spd_log::info("Destroy Order Consumer instance {} OK", instanceIndex_);
}
#ifdef __cplusplus
@@ -70,7 +70,7 @@ int order_consumer_on_message(void *thread, void *opaque, char *topic, char *use
case Success:
return 0;
case Suspend:
- spdlog::info("Consume Order Message failed, Topic:{}, MessageId:{}, RecosumeTimes:{}",
+ rocketmq::spd_log::info("Consume Order Message failed, Topic:{}, MessageId:{}, RecosumeTimes:{}",
message_.getTopic(), message_.getMsgID(), message_.getReconsumeTimes());
return 1;
default:
@@ -104,5 +104,5 @@ void OrderConsumerImpl::subscribe(const char *topic, const char *subExpression,
graal_isolatethread_t *thread_;
ThreadAttachment attachment(&thread_);
::subscribe_order_listener(thread_, instanceIndex_, &sub);
- spdlog::info("Subscribe OK, InstanceID:{}, Topic:{}, SubExpression:{}", instanceIndex_, topic, subExpression);
+ rocketmq::spd_log::info("Subscribe OK, InstanceID:{}, Topic:{}, SubExpression:{}", instanceIndex_, topic, subExpression);
}
\ No newline at end of file
diff --git a/src/main/cpp/sdk/OrderProducerImpl.cpp b/src/main/cpp/sdk/OrderProducerImpl.cpp
index 2e78f6f..d0d6414 100644
--- a/src/main/cpp/sdk/OrderProducerImpl.cpp
+++ b/src/main/cpp/sdk/OrderProducerImpl.cpp
@@ -33,7 +33,7 @@ OrderProducerImpl::OrderProducerImpl(ONSFactoryProperty factoryProperty) throw(o
factory_property fp;
FactoryPropertyConverter converter(factoryProperty, fp);
instanceIndex_ = create_order_producer(thread_, &fp);
- spdlog::info("Create Order Producer OK, InstanceId:{}, ProducerID:{}, NameServer:{}",
+ rocketmq::spd_log::info("Create Order Producer OK, InstanceId:{}, ProducerID:{}, NameServer:{}",
instanceIndex_, factoryProperty.getProducerId(), factoryProperty.getNameSrvAddr());
}
@@ -49,7 +49,7 @@ void OrderProducerImpl::shutdown() {
graal_isolatethread_t *thread_;
ThreadAttachment attachment(&thread_);
destroy_instance(thread_, instanceIndex_);
- spdlog::info("Destroy Order Producer instance {} OK", instanceIndex_);
+ rocketmq::spd_log::info("Destroy Order Producer instance {} OK", instanceIndex_);
}
SendResultONS OrderProducerImpl::send(Message &msg, std::string shardingKey) throw(ons::ONSClientException) {
@@ -64,7 +64,7 @@ SendResultONS OrderProducerImpl::send(Message &msg, std::string shardingKey) thr
ONSClientException clientException(std::string(sendResult.error_msg), sendResult.error_no);
throw clientException;
}
- spdlog::debug("Send message OK. MsgId: {}", sendResult.message_id);
+ rocketmq::spd_log::debug("Send message OK. MsgId: {}", sendResult.message_id);
SendResultONS sendResultOns;
sendResultOns.setMessageId(std::string(sendResult.message_id));
return sendResultOns;
diff --git a/src/main/cpp/sdk/ProducerImpl.cpp b/src/main/cpp/sdk/ProducerImpl.cpp
index cd4085a..29c3868 100644
--- a/src/main/cpp/sdk/ProducerImpl.cpp
+++ b/src/main/cpp/sdk/ProducerImpl.cpp
@@ -35,7 +35,7 @@ ProducerImpl::ProducerImpl(ONSFactoryProperty factoryProperty) throw(ons::ONSCli
factory_property fp;
FactoryPropertyConverter converter(factoryProperty, fp);
instanceIndex_ = create_producer(thread_, &fp);
- spdlog::info("Create Producer OK, InstanceId:{}, ProducerID:{}, NameServer:{}",
+ rocketmq::spd_log::info("Create Producer OK, InstanceId:{}, ProducerID:{}, NameServer:{}",
instanceIndex_, factoryProperty.getProducerId(), factoryProperty.getNameSrvAddr());
}
@@ -51,7 +51,7 @@ void ProducerImpl::shutdown() {
graal_isolatethread_t *thread_;
ThreadAttachment attachment(&thread_);
destroy_instance(thread_, instanceIndex_);
- spdlog::info("Destroy Producer instance {} OK", instanceIndex_);
+ rocketmq::spd_log::info("Destroy Producer instance {} OK", instanceIndex_);
}
ons::SendResultONS ProducerImpl::send(Message &msg) throw(ONSClientException) {
@@ -65,7 +65,7 @@ ons::SendResultONS ProducerImpl::send(Message &msg) throw(ONSClientException) {
if (sendResult.error_no) {
throw ONSClientException(std::string(sendResult.error_msg), sendResult.error_no);
}
- spdlog::debug("Send message OK. MsgId: {}", sendResult.message_id);
+ rocketmq::spd_log::debug("Send message OK. MsgId: {}", sendResult.message_id);
SendResultONS sendResultOns;
sendResultOns.setMessageId(std::string(sendResult.message_id));
return sendResultOns;
diff --git a/src/main/cpp/sdk/TransactionProducerImpl.cpp b/src/main/cpp/sdk/TransactionProducerImpl.cpp
index 31f8db8..c0c5178 100644
--- a/src/main/cpp/sdk/TransactionProducerImpl.cpp
+++ b/src/main/cpp/sdk/TransactionProducerImpl.cpp
@@ -61,7 +61,7 @@ namespace ons {
void *checker = reinterpret_cast<void *>(pTransactionCheckListener);
void *transaction_check = (void *) transaction_check_func;
instanceIndex_ = create_transaction_producer(thread_, &fp, checker, transaction_check);
- spdlog::info("Create Transaction Producer OK, InstanceId:{}, ProducerID:{}, NameServer:{}",
+ rocketmq::spd_log::info("Create Transaction Producer OK, InstanceId:{}, ProducerID:{}, NameServer:{}",
instanceIndex_, factoryProperty.getProducerId(), factoryProperty.getNameSrvAddr());
}
@@ -76,7 +76,7 @@ namespace ons {
graal_isolatethread_t *thread_;
ThreadAttachment attachment(&thread_);
destroy_instance(thread_, instanceIndex_);
- spdlog::info("Destroy Transaction Producer instance {} OK", instanceIndex_);
+ rocketmq::spd_log::info("Destroy Transaction Producer instance {} OK", instanceIndex_);
}
SendResultONS TransactionProducerImpl::send(Message &msg, LocalTransactionExecuter *pTransactionExecutor) {
diff --git a/src/main/cpp/sdk/common/Logger.h b/src/main/cpp/sdk/common/Logger.h
index 2d90237..f547c9b 100644
--- a/src/main/cpp/sdk/common/Logger.h
+++ b/src/main/cpp/sdk/common/Logger.h
@@ -61,6 +61,66 @@ namespace rocketmq {
static void flushLogger();
+ template<typename... Args>
+ static inline void trace(const char *fmt, const Args &... args) {
+ spdlog::trace(fmt, args...);
+ }
+
+ template<typename... Args>
+ static inline void debug(const char *fmt, const Args &... args) {
+ spdlog::debug(fmt, args...);
+ }
+
+ template<typename... Args>
+ static inline void info(const char *fmt, const Args &... args) {
+ spdlog::info(fmt, args...);
+ }
+
+ template<typename... Args>
+ static inline void warn(const char *fmt, const Args &... args) {
+ spdlog::warn(fmt, args...);
+ }
+
+ template<typename... Args>
+ static inline void error(const char *fmt, const Args &... args) {
+ spdlog::error(fmt, args...);
+ }
+
+ template<typename... Args>
+ static inline void critical(const char *fmt, const Args &... args) {
+ spdlog::critical(fmt, args...);
+ }
+
+ template<typename T>
+ static inline void trace(const T &msg) {
+ spdlog::trace(msg);
+ }
+
+ template<typename T>
+ static inline void debug(const T &msg) {
+ spdlog::debug(msg);
+ }
+
+ template<typename T>
+ static inline void info(const T &msg) {
+ spdlog::info(msg);
+ }
+
+ template<typename T>
+ static inline void warn(const T &msg) {
+ spdlog::warn(msg);
+ }
+
+ template<typename T>
+ static inline void error(const T &msg) {
+ spdlog::error(msg);
+ }
+
+ template<typename T>
+ static inline void critical(const T &msg) {
+ spdlog::critical(msg);
+ }
+
private:
static int isDir(std::string path);
diff --git a/src/main/cpp/sdk/common/UtilAll.h b/src/main/cpp/sdk/common/UtilAll.h
index 45baebe..dae436b 100644
--- a/src/main/cpp/sdk/common/UtilAll.h
+++ b/src/main/cpp/sdk/common/UtilAll.h
@@ -60,7 +60,7 @@ namespace ons {
static graal_isolate_t *singleton = nullptr;
if (nullptr == singleton) {
if (graal_create_isolate(nullptr, &singleton, nullptr)) {
- spdlog::error("Failed to create graal isolate");
+ rocketmq::spd_log::error("Failed to create graal isolate");
return nullptr;
}
}
@@ -168,7 +168,7 @@ namespace ons {
++isolate_thread_ref_cnt;
if (graal_attach_thread(UtilAll::get_isolate(), thread)) {
- spdlog::error("Failed to attach native thread {} to graal isolate", ss.str());
+ rocketmq::spd_log::error("Failed to attach native thread {} to graal isolate", ss.str());
throw ons::ONSClientException("attach thread to isolate failed", -1);
}
@@ -176,7 +176,7 @@ namespace ons {
pthread_key_create(&key, &ThreadAttachment::detach);
pthread_setspecific(key, &ThreadAttachment::isolate_thread_ref_cnt);
- spdlog::debug("Attach thread {} to isolate OK", ss.str());
+ rocketmq::spd_log::debug("Attach thread {} to isolate OK", ss.str());
}
~ThreadAttachment() {
@@ -188,7 +188,7 @@ namespace ons {
graal_detach_thread(attached);
std::stringstream ss;
ss << std::this_thread::get_id();
- spdlog::debug("Detach thread {} from isolate OK", ss.str());
+ rocketmq::spd_log::debug("Detach thread {} from isolate OK", ss.str());
}
}
diff --git a/src/test/cpp/LoggerTest.cpp b/src/test/cpp/LoggerTest.cpp
index 8e9d1cb..bd9c963 100644
--- a/src/test/cpp/LoggerTest.cpp
+++ b/src/test/cpp/LoggerTest.cpp
@@ -5,5 +5,5 @@
TEST(LoggerTest, testLog) {
rocketmq::spd_log::initLogger();
- spdlog::debug("This is a debug line");
+ rocketmq::spd_log::debug("This is a debug line");
}
\ No newline at end of file