make log dir configurable and make log name compatible with RocketMQ main project (#401)
diff --git a/build.sh b/build.sh
index cba481e..be500a6 100755
--- a/build.sh
+++ b/build.sh
@@ -32,7 +32,7 @@
declare fname_openssl_down="openssl-1.1.1d.tar.gz"
declare fname_libevent_down="release-2.1.11-stable.zip"
declare fname_jsoncpp_down="0.10.7.zip"
-declare fname_boost_down="1.58.0/boost_1_58_0.tar.gz"
+declare fname_boost_down="1.78.0/boost_1_78_0.tar.gz"
PrintParams() {
echo "=========================================one key build help============================================"
diff --git a/src/common/ByteOrder.h b/src/common/ByteOrder.h
index 16a5184..9263822 100644
--- a/src/common/ByteOrder.h
+++ b/src/common/ByteOrder.h
@@ -20,7 +20,7 @@
#include <stddef.h>
#include <stdint.h>
#include <algorithm>
-#include <boost/detail/endian.hpp>
+#include <boost/endian/arithmetic.hpp>
#include "RocketMQClient.h"
#include "UtilAll.h"
//==============================================================================
diff --git a/src/common/UtilAll.h b/src/common/UtilAll.h
index ec4ea30..58e62ab 100644
--- a/src/common/UtilAll.h
+++ b/src/common/UtilAll.h
@@ -67,6 +67,7 @@
const string DEFAULT_CLIENT_KEY_FILE = "/etc/rocketmq/client.key";
const string DEFAULT_CLIENT_CERT_FILE = "/etc/rocketmq/client.pem";
const string DEFAULT_CA_CERT_FILE = "/etc/rocketmq/ca.pem";
+const string ROCKETMQ_CLIENT_LOG_DIR = "ROCKETMQ_CLIENT_LOG_DIR";
const string WS_ADDR =
"please set nameserver domain by setDomainName, there is no default "
"nameserver domain";
diff --git a/src/extern/CProducer.cpp b/src/extern/CProducer.cpp
index 58d00b6..7834f33 100644
--- a/src/extern/CProducer.cpp
+++ b/src/extern/CProducer.cpp
@@ -687,6 +687,7 @@
if (producer == NULL) {
return NULL_POINTER;
}
+ setenv(ROCKETMQ_CLIENT_LOG_DIR.c_str(), logPath, 1);
return OK;
}
diff --git a/src/extern/CPullConsumer.cpp b/src/extern/CPullConsumer.cpp
index a0db242..ddf39d0 100644
--- a/src/extern/CPullConsumer.cpp
+++ b/src/extern/CPullConsumer.cpp
@@ -20,6 +20,7 @@
#include "CMessageExt.h"
#include "DefaultMQPullConsumer.h"
#include "MQClientErrorContainer.h"
+#include "Logging.h"
using namespace rocketmq;
using namespace std;
@@ -114,6 +115,7 @@
}
// Todo, This api should be implemented by core api.
//((DefaultMQPullConsumer *) consumer)->setInstanceName(instanceName);
+ setenv(ROCKETMQ_CLIENT_LOG_DIR.c_str(), logPath, 1);
return OK;
}
diff --git a/src/extern/CPushConsumer.cpp b/src/extern/CPushConsumer.cpp
index 77da3af..9065804 100644
--- a/src/extern/CPushConsumer.cpp
+++ b/src/extern/CPushConsumer.cpp
@@ -21,6 +21,7 @@
#include "CMessageExt.h"
#include "DefaultMQPushConsumer.h"
#include "MQClientErrorContainer.h"
+#include "Logging.h"
using namespace rocketmq;
using namespace std;
@@ -278,6 +279,7 @@
}
// Todo, This api should be implemented by core api.
//((DefaultMQPushConsumer *) consumer)->setInstanceName(instanceName);
+ setenv(ROCKETMQ_CLIENT_LOG_DIR.c_str(), logPath, 1);
return OK;
}
diff --git a/src/log/Logging.cpp b/src/log/Logging.cpp
index 9ecd1d8..34ab25f 100644
--- a/src/log/Logging.cpp
+++ b/src/log/Logging.cpp
@@ -38,16 +38,19 @@
}
logAdapter::logAdapter() : m_logLevel(eLOG_LEVEL_INFO) {
+ setLogDir();
string homeDir(UtilAll::getHomeDirectory());
- homeDir.append("/logs/rocketmq-cpp/");
+ homeDir.append(m_log_dir);
m_logFile += homeDir;
- std::string fileName = UtilAll::to_string(getpid()) + "_" + "rocketmq-cpp.log.%N";
+ std::string fileName = "rocketmq_client.log";
m_logFile += fileName;
// boost::log::expressions::attr<
// boost::log::attributes::current_thread_id::value_type>("ThreadID");
boost::log::register_simple_formatter_factory<boost::log::trivial::severity_level, char>("Severity");
- m_logSink = logging::add_file_log(keywords::file_name = m_logFile, keywords::rotation_size = 100 * 1024 * 1024,
+ m_logSink = logging::add_file_log(keywords::file_name = m_logFile,
+ keywords::target_file_name = "rocketmq_client_%Y%m%d-%N.log",
+ keywords::rotation_size = 100 * 1024 * 1024,
keywords::time_based_rotation = sinks::file::rotation_at_time_point(0, 0, 0),
keywords::format = "[%TimeStamp%](%Severity%):%Message%",
keywords::min_free_space = 300 * 1024 * 1024, keywords::target = homeDir,
@@ -99,9 +102,23 @@
return m_logLevel;
}
+void logAdapter::setLogDir() {
+ char* p = nullptr;
+ if ((p = getenv(ROCKETMQ_CLIENT_LOG_DIR.c_str()))) {
+ m_log_dir = p;
+ }
+ if (!m_log_dir.empty()) {
+ if (m_log_dir[m_log_dir.length() - 1] != '/') {
+ m_log_dir += '/';
+ }
+ } else {
+ m_log_dir = "/logs/rocketmq-client/";
+ }
+}
+
void logAdapter::setLogFileNumAndSize(int logNum, int sizeOfPerFile) {
string homeDir(UtilAll::getHomeDirectory());
- homeDir.append("/logs/rocketmq-cpp/");
+ homeDir.append(m_log_dir);
m_logSink->locked_backend()->set_file_collector(sinks::file::make_collector(
keywords::target = homeDir, keywords::max_size = logNum * sizeOfPerFile * 1024 * 1024));
}
diff --git a/src/log/Logging.h b/src/log/Logging.h
index 24960c7..a6aec39 100644
--- a/src/log/Logging.h
+++ b/src/log/Logging.h
@@ -45,6 +45,7 @@
public:
~logAdapter();
static logAdapter* getLogInstance();
+ void setLogDir();
void setLogLevel(elogLevel logLevel);
elogLevel getLogLevel();
void setLogFileNumAndSize(int logNum, int sizeOfPerFile);
@@ -60,6 +61,7 @@
boost::shared_ptr<logSink_t> m_logSink;
static logAdapter* alogInstance;
static boost::mutex m_imtx;
+ std::string m_log_dir;
};
#define ALOG_ADAPTER logAdapter::getLogInstance()