This is an automated email from the ASF dual-hosted git repository.

dockerzhang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/inlong.git


The following commit(s) were added to refs/heads/master by this push:
     new 520e659a82 [INLONG-8860][SDK] Add log utils for dataproxy cpp sdk 
(#8862)
520e659a82 is described below

commit 520e659a82bbc7a1188149f5402ac2f67d200c93
Author: doleyzi <[email protected]>
AuthorDate: Sat Sep 9 18:04:27 2023 +0800

    [INLONG-8860][SDK] Add log utils for dataproxy cpp sdk (#8862)
    
    Co-authored-by: doleyzi <[email protected]>
---
 .../dataproxy-sdk-cpp/src/uitls/capi_constant.h    | 80 ++++++++++++++++++
 .../dataproxy-sdk-cpp/src/uitls/logger.h           | 97 ++++++++++++++++++++++
 2 files changed, 177 insertions(+)

diff --git 
a/inlong-sdk/dataproxy-sdk-twins/dataproxy-sdk-cpp/src/uitls/capi_constant.h 
b/inlong-sdk/dataproxy-sdk-twins/dataproxy-sdk-cpp/src/uitls/capi_constant.h
new file mode 100644
index 0000000000..2f191909ba
--- /dev/null
+++ b/inlong-sdk/dataproxy-sdk-twins/dataproxy-sdk-cpp/src/uitls/capi_constant.h
@@ -0,0 +1,80 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef INLONG_SDK_CONSTANT_H
+#define INLONG_SDK_CONSTANT_H
+
+#include "string.h"
+#include <stdint.h>
+
+namespace inlong {
+namespace constants {
+static const int32_t kMaxRequestTDMTimes = 4;
+static const char kAttrFormat[] =
+    "__addcol1__reptime=yyyymmddHHMMSS&__addcol2_ip=xxx.xxx.xxx.xxx";
+static const int32_t kAttrLen = strlen(kAttrFormat);
+
+static const char kVersion[] = "inlong-sdk-cpp-v3.2";
+static const uint16_t kBinaryMagic = 0xEE01;
+static const uint32_t kBinPackMethod = 7;
+static const uint8_t kBinSnappyFlag = 1 << 5;
+
+static const int32_t kPerGroupidThreadNums = 1;
+static const int32_t kSendBufSize = 10240000;
+static const int32_t kRecvBufSize = 10240000;
+
+static const int32_t kDispatchIntervalZip = 8;
+static const int32_t kDispatchIntervalSend = 10;
+
+static const bool kEnablePack = true;
+static const uint32_t kPackSize = 409600;
+static const uint32_t kPackTimeout = 3000;
+static const uint32_t kExtPackSize = 409600;
+
+static const bool kEnableZip = true;
+static const uint32_t kMinZipLen = 512;
+
+static const uint32_t kLogNum = 5;
+static const uint32_t kLogSize = 100 * 1024 * 1024;
+static const uint8_t kLogLevel = 2;
+static const char kLogPath[] = "./";
+
+static const char kBusURL[] = "127.0.0.1/api/tdbus_ip_v2";
+static const bool kEnableBusURLFromCluster = false;
+static const char kBusClusterURL[] =
+    "127.0.0.1/heartbeat/tdbus_ip_v2?cluster_id=0&net_tag=all";
+static const uint32_t kBusUpdateInterval = 2;
+static const uint32_t kBusURLTimeout = 5;
+static const uint32_t kMaxBusNum = 200;
+
+static const bool kEnableTCPNagle = true;
+static const uint32_t kTcpIdleTime = 600000;
+static const uint32_t kTcpDetectionInterval = 60000;
+
+static const char kSerIP[] = "127.0.0.1";
+static const uint32_t kSerPort = 46801;
+static const uint32_t kMsgType = 7;
+
+static const bool kEnableSetAffinity = false;
+static const uint32_t kMaskCPUAffinity = 0xff;
+static const uint16_t kExtendField = 0;
+
+} // namespace constants
+} // namespace inlong
+#endif // INLONG_SDK_CONSTANT_H
\ No newline at end of file
diff --git 
a/inlong-sdk/dataproxy-sdk-twins/dataproxy-sdk-cpp/src/uitls/logger.h 
b/inlong-sdk/dataproxy-sdk-twins/dataproxy-sdk-cpp/src/uitls/logger.h
new file mode 100644
index 0000000000..59bcbdc753
--- /dev/null
+++ b/inlong-sdk/dataproxy-sdk-twins/dataproxy-sdk-cpp/src/uitls/logger.h
@@ -0,0 +1,97 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#pragma once
+#ifndef INLONG_SDK_LOGGER_H
+#define INLONG_SDK_LOGGER_H
+
+#include "sdk_conf.h"
+#include <log4cplus/fileappender.h>
+#include <log4cplus/helpers/loglog.h>
+#include <log4cplus/initializer.h>
+#include <log4cplus/log4cplus.h>
+#include <log4cplus/logger.h>
+#include <log4cplus/loglevel.h>
+using namespace log4cplus::helpers;
+
+namespace inlong {
+static void initLog4cplus() {
+  std::string log_path = SdkConfig::getInstance()->log_path_;
+  if (log_path.back() != '/') {
+    log_path = "./inlong-sdk-logs/";
+  }
+  std::string log_name = log_path + "/inlong-sdk.log";
+  log4cplus::SharedAppenderPtr the_append(new log4cplus::RollingFileAppender(
+      log_name, SdkConfig::getInstance()->log_size_,
+      SdkConfig::getInstance()->log_num_));
+  log4cplus::tstring pattern =
+      LOG4CPLUS_TEXT("%D{%m-%d %H:%M:%S:%Q} %m [%b:%L]\n");
+  the_append->setLayout(
+      std::auto_ptr<log4cplus::Layout>(new log4cplus::PatternLayout(pattern)));
+  switch (SdkConfig::getInstance()->log_level_) {
+  case 0:
+    log4cplus::Logger::getRoot().setLogLevel(log4cplus::ERROR_LOG_LEVEL);
+    break;
+  case 1:
+    log4cplus::Logger::getRoot().setLogLevel(log4cplus::WARN_LOG_LEVEL);
+    break;
+  case 2:
+    log4cplus::Logger::getRoot().setLogLevel(log4cplus::INFO_LOG_LEVEL);
+    break;
+  case 3:
+    log4cplus::Logger::getRoot().setLogLevel(log4cplus::DEBUG_LOG_LEVEL);
+    break;
+  default:
+    log4cplus::Logger::getRoot().setLogLevel(log4cplus::INFO_LOG_LEVEL);
+    break;
+  }
+
+  log4cplus::Logger::getRoot().addAppender(the_append);
+}
+
+#define LOG_ERROR(x)                                                           
\
+  {                                                                            
\
+    std::stringstream _log_ss;                                                 
\
+    _log_ss << "ERROR " << x;                                                  
\
+    LOG4CPLUS_ERROR(log4cplus::Logger::getRoot(), _log_ss.str());              
\
+  }
+
+#define LOG_WARN(x)                                                            
\
+  {                                                                            
\
+    std::stringstream _log_ss;                                                 
\
+    _log_ss << "WARN " << x;                                                   
\
+    LOG4CPLUS_WARN(log4cplus::Logger::getRoot(), _log_ss.str());               
\
+  }
+
+#define LOG_INFO(x)                                                            
\
+  {                                                                            
\
+    std::stringstream _log_ss;                                                 
\
+    _log_ss << "INFO " << x;                                                   
\
+    LOG4CPLUS_INFO(log4cplus::Logger::getRoot(), _log_ss.str());               
\
+  }
+
+#define LOG_DEBUG(x)                                                           
\
+  {                                                                            
\
+    std::stringstream _log_ss;                                                 
\
+    _log_ss << "DEBUG " << x;                                                  
\
+    LOG4CPLUS_DEBUG(log4cplus::Logger::getRoot(), _log_ss.str());              
\
+  }
+
+} // namespace inlong
+#endif // INLONG_SDK_LOGGER_H
\ No newline at end of file

Reply via email to