ohpm install @farmerx/tencntcloud-cls-sdk-ohos
import { TencntcloudLog, LogCallback } from "@farmerx/tencntcloud-cls-sdk-ohos"
Variable | Type | Required | Description |
endpoint | String | Yes | Regional information. For completion, see the domain name in the API upload log Tab under available region. |
access_secret | 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. |
access_key | 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. |
access_token | String | No | Temporary key token. For example, use temporary key to auto-fill. |
topic_id | String | Yes | Log topic ID information. |
import {LogProducer} from "@farmerx/tencntcloud-cls-sdk-ohos";// Initializelet producer = new LogProducer("#[topic_id]","#[access_key]","#[access_secret]","#[access_token]","","#[endpoint]", 100, 100, 2000)// Set the callback functionproducer.setCallback((err: Error | null, topicID: string, code: number, request_id: string, errorMessage: string) => {if (err==null) {hilog.info(0x0000,'testTagCLS','onLogCallback.topic: %{public}s , code: %{public}d, request_id: %{public}s, errorMessage: %{public}s',topicID, code, request_id, errorMessage);} else {hilog.info(0x0000,'testTagCLS','onLogCallback.topic: %{public}s, code: %{public}d, request_id: %{public}s, errorMessage: %{public}s',topicID, code, request_id, err.message);}})// Set the source IPproducer.setSourceIp("127.0.0.3")// reset access keyproducer.setAccessKey("#[access_key]", "#[access_secret]", "#[access_token]");// Synchronous sendingfunction syncsencLog() {let logs: Record<string, string>[] = [];let log: Record<string, string> = {};// Add key-value pairlog["key1"] = "value1";log["key2"] = "value2";log["key3"] = "value3";logs.push(log)try {let rsp = producer.syncSendLogs( "127.0.0.1", logs)hilog.info(0x0000, 'testTag', "========%{public}s, %{public}s", rsp.requestId, rsp.rspText)} catch (e) {// ....}}// Async sendfunction asyncSendLog() {let log: Record<string, string> = {};// Add key-value pairlog["key1"] = "value1";log["key2"] = "value2";log["key3"] = "value3";try {producer.addLog(log)} catch (e) {// ....}}asyncSendLog()sencLog()
Feedback