sudo yum groupinstall "Development Tools"sudo yum install glibc-devel cmake openssl-devel gitsudo yum install libcurl-devel
git clone https://github.com/TencentCloud/tencentcloud-cls-sdk-c.git
cd tencentcloud-cls-sdk-c/demo
cd ..# Generate build filescmake .# Compile the SDKmake
# Enter the executable file directorycd build/binRun program./post_log_demo
Variable | Type | Required | Description |
Endpoint | String | Yes | Domain information, fill in please refer to available region for the domain name in the Log upload via API Tab. |
AccessId | String | Yes | TencentCloud API key information. For key information acquisition, please visit API Key Management. Please ensure the associated account has appropriate SDK log upload permission. |
AccessKey | String | Yes | TencentCloud API key information. For key information acquisition, please visit API Key Management. Please ensure the associated account has appropriate SDK log upload permission. |
Topic | String | Yes | Log topic ID info. |
#include "log_producer_config.h"#include "log_producer_client.h"#include "log_error.h"#include <stdio.h>#include <stdlib.h>void callback(const char *config_name, int result, size_t log_bytes, size_t compressed_bytes, const char *req_id, const char *message, const unsigned char *raw_buffer){if (result == LOG_PRODUCER_OK){if (req_id == NULL){req_id = "";}printf("send success, config : %s, result : %d, log bytes : %d, compressed bytes : %d, request id : %s \\n",config_name, (result),(int)log_bytes, (int)compressed_bytes, req_id);}else{if (message == NULL){message = "";}if (req_id == NULL){req_id = "";}printf("send fail, config : %s, result : %d, log bytes : %d, compressed bytes : %d, request id : %s, error message : %s\\n",config_name, (result),(int)log_bytes, (int)compressed_bytes, req_id, message);}}clslogproducer *ConstructorLogProducer(SendCallBackFunc notifyFunc){//Call the malloc function to allocate memory and initialize the default configurationProducerConfig *config = ConstructLogConfig();// Fill in domain information, see the domain name in the Log upload via API Tab: https://www.tencentcloud.com/document/product/614/18940?from_cn_redirect=1#.E5.9F.9F.E5.90.8DSetEndpoint(config, "ap-xxxxxxxxx.cls.tencentcs.com");// Fill in the cloud API key information. For key information acquisition, please visit: https://console.tencentcloud.com/cam/capi// Please ensure the associated account has appropriate log upload permissions. For the permission configuration guide, see: https://www.tencentcloud.com/document/product/614/68374?from_cn_redirect=1#.E4.BD.BF.E7.94.A8-api-.E4.B8.8A.E4.BC.A0.E6.95.B0.E6.8D.AE// This example retrieves from environmental variables. For environment variable configuration, see https://www.tencentcloud.com/document/product/614/113851?from_cn_redirect=1SetAccessId(config, getenv("TENCENTCLOUD_SECRET_ID"));SetAccessKey(config, getenv("TENCENTCLOUD_SECRET_KEY"));// Set the topic ID for log upload, replace with your Topic IDSetTopic(config, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");SetPackageLogBytes(config, 4 * 1024 * 1024);setPackageTimeout(config, 3000);SetMaxBufferLimit(config, 64 * 1024 * 1024);set_send_thread_count(config, 4);SetCompressType(config, 1);SetConnectTtimeoutSec(config, 10);SetSendTimeoutSec(config, 15);return ConstructorClsLogProducer(config, notifyFunc, NULL);}void post_logs(){if (ClsLogProducerInit(LOG_GLOBAL_ALL) != LOG_PRODUCER_OK){printf("ClsLogProducerInit init fail \\n");exit(1);}clslogproducer *producer = ConstructorLogProducer(callback);if (producer == NULL){printf("create log producer by config fail \\n");exit(1);}clslogproducerclient *client = GetClsLogProducer(producer, NULL);if (client == NULL){printf("create log producer client by config fail \\n");exit(1);}int i = 0;for (; i < 10; ++i){char indexStr[32];sprintf(indexStr, "%d", i);int rst = PostClsLog(client, 20, "key1", "value_1","key2", "value_2","key3", "value_3","key4", "value_4","key5", "value_5","key6", "value_6","key7", "value_7","key8", "value_8","key9", "value_9","index", indexStr);if (rst != LOG_PRODUCER_OK){printf("add log error %d \\n", rst);}}DestructorClsLogProducer(producer);ClsLogProducerDestroy();}int main(int argc, char *argv[]){post_logs();return 0;}
Feedback