# 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-mini
Variable | Type | Required | Description |
endpoint | String | Yes | Domain information. Fill in the domain name in the available region under the Log upload via API Tab. |
retry_times | integer | Yes | Maximum number of retries |
Source | String | No | Source IP |
topicID | String | Yes | Log topic ID information. |
const { Log, LogGroup, AsyncClient, PutLogsRequest } = require('tencentcloud-cls-sdk-js-mini');// Create an AsyncClient instancelet client = new AsyncClient({endpoint: "ap-xxxxxx.cls.tencentcs.com", // 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.8Dretry_times: 10,});// Create a LogGroup instancelet logGroup = new LogGroup();logGroup.setSource("1.XX.XX.XX"); // Replace with your IP address// Create a Log instancelet log = new Log(Date.now());log.addContent("hello", "hello world1");log.addContent("world", "hello world2");// Add Log to LogGrouplogGroup.addLog(log);// Create a PutLogsRequest instancelet request = new PutLogsRequest("8bbfXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", logGroup); // replace with your log topic ID// Upload logsasync function uploadLogs() {try {let data = await client.PutLogs(request);console.log("Logs uploaded successfully:", data);} catch (error) {console.error("Error uploading logs:", error);}}// Call the log upload functionuploadLogs();
Feedback