# Install EPEL repositorysudo yum install epel-release -y# Install Node.js and npmsudo yum install nodejs npm -y
git clone https://github.com/TencentCloud/tencentcloud-cls-sdk-js.gitcd tencentcloud-cls-sdk-js
npm installnpm install tencentcloud-cls-sdk-js-web
Variable | Type | Required | Description |
endpoint | String | Yes | Domain information. For details, fill in the domain name in the available region under the API Log Upload Tab. |
retry_times | integer | Yes | Maximum number of retries |
Source | String | No | Source IP address. |
topicID | String | Yes | Log topic ID info. |
const { Log, LogGroup, AsyncClient, PutLogsRequest } = require('tencentcloud-cls-sdk-js-web');// Create an AsyncClient instancelet client = new AsyncClient({endpoint: "ap-xxxxxxx.cls.tencentcs.com", // fill in domain information, completion guide: https://www.tencentcloud.com/document/product/614/18940?from_cn_redirect=1#.E5.9F.9F.E5.90.8D, see domain in the Log upload via API Tab of the linkretry_times: 10,});// Create a LogGroup instancelet logGroup = new LogGroup();logGroup.setSource("1.X.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("8bbXXXXXXXXXXXXXXXXXXXXXXXXXXXX", logGroup); // Replace with your topicID// 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