# Install EPEL repositorysudo yum install epel-release -y# Install Node.js and npmsudo yum install nodejs npm -y
cd tencentcloud-cls-sdk-js
npm installnpm install tencentcloud-cls-sdk-js
Variable | Type | Required | Description |
endpoint | String | Yes | Domain information. For completion, see the domain name in the API upload log Tab under available region. |
secretId | String | Yes | TencentCloud API key information. For key information acquisition, visit API key management. Ensure the associated account has appropriate SDK log upload permission. |
secretKey | String | Yes | TencentCloud API key information. For key information acquisition, visit API key management. Ensure the associated account has appropriate SDK log upload permission. |
sourceIp | String | No | Source IP address. |
retry_times | integer | Yes | Maximum number of retries |
topicID | String | Yes | Log topic ID information. |
const { AsyncClient, LogItem, LogGroup, Content, PutLogsRequest } = require('tencentcloud-cls-sdk-js');// CLS log topic ID; required parameterlet topicID = "591XXXXXXXXXXXXXXXXXXXXXXXXXXXX"; // replace with your log topic IDlet client = new AsyncClient({// 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.8Dendpoint: "ap-xxxxxx.cls.tencentcs.com",// Fill in TencentCloud API key information. For key information acquisition, please visit: https://console.tencentcloud.com/cam/capi// Ensure the associated account has appropriate log upload permissions. Permission configuration guide: 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 variable. Environment variable configuration guide: https://www.tencentcloud.com/document/product/614/113851?from_cn_redirect=1secretId: process.env.TENCENTCLOUD_SECRET_ID,secretKey: process.env.TENCENTCLOUD_SECRET_KEY,// source IP address: optional parameter, leave blank for automatic filling with local IP addresssourceIp: "127.XX.XX.1",// retry count: required parameterretry_times: 10,});async function sendLog() {let item = new LogItem();item.pushBack(new Content("__CONTENT__", "This is the log content to be sent")); // Change to the log content you want to senditem.setTime(Math.floor(Date.now() / 1000));let loggroup = new LogGroup();loggroup.addLogs(item);let request = new PutLogsRequest(topicID, loggroup);try {let data = await client.PutLogs(request);console.log("Log sent successfully:", data);} catch (error) {console.error("Failed to send log:", error);}}call the send log functionsendLog();
Feedback