If your function was created before January 29, 2021 and has not been migrated, but you need to use more log analysis features, please see Log Delivery Configuration (Legacy) to deliver function invocation logs to Cloud Log Service (CLS).
SCF was fully connected to Tencent Cloud CLS starting from January 29, 2021. After then, the invocation logs of newly created functions will be delivered to CLS, and logs can be output in real time. The existing functions are gradually migrated by regions. For more information, please see SCF Log Service Change Notification.
To view the logs normally, please ensure that the sub-account at least has the read-only permission of CLS
QcloudCLSReadOnlyAccess. For how the root account grant permissions for the sub-account, see Authorization Management.
Delivering function invocation logs to CLS has the following limits:
Please pay attention to whether the CLS configuration can meet your business needs. Exceeding the limits may cause log write failures.
When creating a function, if you don't specify the destination topic for log delivery, the default log delivery capability will be used. For default log delivery, SCF will activate the CLS service for you and deliver the function invocation logs to the log topic under the SCF-specific logset. The SCF-specific logset and log topic are prefixed with
SCF_logtopic respectively, and will be created automatically if they do not exist. Function invocation logs will be retained for 7 days by default, and you can view and manage them on the CLS console.
CLS is billed separately, and the SCF-specific log topic will consume the free tier of CLS. For more information, please see CLS Billing Overview.
You can click the logset ID in Log Configuration in Function Configuration to enter the CLS console to view and manage logs. The SCF-specific logset is marked with the word
SCF in the CLS console. If you need to persistently store, deliver, or consume logs or monitor and set alarms on log content, you can complete the configuration in the CLS console.
When creating a function, if you need to specify the destination log topic to deliver function invocation logs, you can use the custom log delivery capability. Before using this capability, you should make sure that the CLS service has been activated.
For the logset region, please select the region where the SCF service is located. Cross-region log push is not supported currently.
SCF-testas an example, as shown below:
Log search depends on the index configuration of the log topic. SCF will automatically complete the index configuration when you create a function. If the index is exceptional and logs cannot be viewed properly, please configure the index in the following steps:
The configuration method in step 4 is only valid for scenarios where there are function invocation logs in the log topic; otherwise, please manually configure the key-value index by referring to the table below.
|Field Name||Field Type||Description|
|SCF_StartTime||long||Invocation start time|
|SCF_LogTime||long||Log generation time|
|SCF_Duration||long||Function execution duration|
|SCF_MemUsage||double||Function runtime memory|
|SCF_Level||text||Log4J log level. Default value: INFO|
|SCF_Type||text||Log type. Platform: platform log, Custom: user log|
|SCF_StatusCode||long||Status code of function execution|
|SCF_RetryNum||long||Number of retries|
To ensure the display effect of the logs in the SCF console, please toggle on Enable Statistics for the field in the key-value index configuration as shown below: