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 ..# ビルドファイルを生成します。cmake .# SDKをコンパイルします。make
# 実行可能ファイルのディレクトリに入ります。cd build/bin# プログラムを実行します。./post_log_demo
変数 | タイプ | 必須/任意 | 説明 |
Endpoint | String | はい | |
AccessId | String | はい | TencentCloud APIキー情報です。キー情報の取得は、APIキー管理で行ってください。また、キーに関連付けられたアカウントに、対応するSDKログアップロード権限が付与されていることを確認してください。 |
AccessKey | String | はい | TencentCloud APIキー情報です。キー情報の取得は、APIキー管理で行ってください。また、キーに関連付けられたアカウントに、対応するSDKログアップロード権限が付与されていることを確認してください。 |
Topic | String | はい | 日志主题的 ID 信息。 |
#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){//malloch関数を呼び出してメモリを確保し、デフォルトの設定を初期化します。ProducerConfig *config = ConstructLogConfig();// ドメイン名情報を入力してください。ドメイン名については、リンク内のAPIアップロードログタブにあるドメイン名を参照してください:https://www.tencentcloud.com/document/product/614/18940#.E5.9F.9F.E5.90.8DSetEndpoint(config, "ap-xxxxxxxxx.cls.tencentcs.com");// TencentCloud APIキー情報を入力してください。キー情報の取得はこちらから:https://console.tencentcloud.com/cam/capi// また、キーに関連付けられたアカウントに、対応するログアップロード権限が付与されていることを確認してください。権限設定ガイド:https://www.tencentcloud.com/document/product/614/45004#.E4.BD.BF.E7.94.A8-api-.E4.B8.8A.E4.BC.A0.E6.95.B0.E6.8D.AE// この例では環境変数から取得します。環境変数設定ガイド:https://www.tencentcloud.com/document/product/614/113851?from_cn_redirect=1SetAccessId(config, getenv("TENCENTCLOUD_SECRET_ID"));SetAccessKey(config, getenv("TENCENTCLOUD_SECRET_KEY"));// アップロードするログのトピックIDを設定し、お客様のTopic IDに置き換えます。SetTopic(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;}
フィードバック