CLS Logs
The interface for querying environment CLS logs can be invoked via commonService.
Log Query
1. Interface Description
Function: Query CLS logs with specified conditions.
Interface declaration: manager.commonService().call({ Action: 'SearchClsLog', Param: {}}): Promise<Object>
⚠️ Starting from version 3.0.0, commonService is used as a method with request parameters (service?: string, version?: string), which constitutes a breaking change.
2. Input Parameters
Field | Required | Type | Description |
---|---|---|---|
EnvId | Yes | String | Environment ID |
StartTime | Required | String | Start time condition for querying, in the format YYYY-MM-DD HH:mm:ss |
EndTime | Required | String | End time condition for querying, in the format YYYY-MM-DD HH:mm:ss |
QueryString | Required | String | Query statement. For details, refer to here |
Limit | Required | String | The number of log entries to return per request. The maximum is 100. |
Sort | Optional | Boolean | Sort by time asc (ascending) or desc (descending). Default is desc. |
UseLucene | Optional | Boolean | Specifies whether to use Lucene syntax. Default is false. |
3. Response
Field | Type | Description |
---|---|---|
RequestId | String | Request unique identifier |
LogResults | String | Log content result |
ILogResObject
Field | Type | Description |
---|---|---|
Context | String | Cursor for fetching more search results |
ListOver | Boolean | Indicates whether all search results have been returned |
Results | Array<ILogObject> | Log content information |
ILogObject
Field | Type | Description |
---|---|---|
TopicId | String | Log topic ID |
TopicName | String | Log topic name |
Timestamp | String | Log time |
Content | String | Log content |
FileName | String | Collection path |
Source | String | Log source device |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const moment = require("moment"); // Date formatting library, requires manual dependency installation
const manager = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId", // CloudBase environment ID, obtain from the Tencent CloudBase Console
});
const { functions } = manager;
async function test() {
const logs = await functions.getFunctionLogs({ name: "your function name" });
const { Data } = logs;
for (let item in Data) {
console.log(item.RequestId);
// Query cls logs based on requestId
const clsLogRes = await manager.commonService().call({
Action: "SearchClsLog",
Param: {
EnvId: cloudBaseConfig.envId,
StartTime: moment(new Date().getTime() - 24 * 60 * 60 * 1000).format(
"YYYY-MM-DD HH:mm:ss"
), // Start time, e.g., one day ago
EndTime: moment().format("YYYY-MM-DD HH:mm:ss"), // End time, e.g., current time
Limit: 100,
Sort: "asc",
QueryString: `requestId:${item.RequestId}`,
},
});
console.log("clsLogRes", clsLogRes);
}
}
test();