tencent cloud

Serverless Cloud Function

Release Notes and Announcements
Release Notes
Announcements
User Guide
Product Introduction
Overview
Related Concepts
How It Works
Strengths
Scenarios
Related Products
Purchase Guide
Billing Overview
Billing Mode
Billable Items and Billing Modes
Function Computing Power Support
Free Tier
SCF Pricing
Billing Example
Payment Overdue
Getting Started
Creating Event Function in Console
User Guide
Quota Management
Managing Functions
Web Function Management
Log Management
Concurrence Management
Trigger Management
Function URL
A Custom Domain Name
Version Management
Alias Management
Permission Management
Running Instance Management
Plugin Management
Managing Monitors and Alarms
Network Configuration
Layer Management
Execution Configuration
Extended Storage Management
DNS Caching Configuration
Resource Managed Mode Management
Near-Offline Resource Hosting Model
Workflow
Triggers
Trigger Overview
Trigger Event Message Structure Summary
API Gateway Trigger
COS Trigger
CLS Trigger
Timer Trigger
CKafka Trigger
Apache Kafka Trigger
MQTT Trigger
Trigger Configuration Description
MPS Trigger
CLB Trigger Description
TencentCloud API Trigger
Development Guide
Basic Concepts
Testing a Function
Environment Variables
Dependency Installation
Using Container Image
Error Types and Retry Policies
Dead Letter Queue
Connecting SCF to Database
Automated Deployment
Cloud Function Status Code
Common Errors and Solutions
Developer Tools
Serverless Web IDE
Calling SDK Across Functions
Third-Party Tools
Code Development
Python
Node.js
Golang
PHP
Java
Custom Runtime
Deploying Image as Function
Web Framework Development
Deploying Framework on Command Line
Quickly Deploying Egg Framework
Quickly Deploying Express Framework
Quickly Deploying Flask Framework
Quickly Deploying Koa Framework
Quickly Deploying Laravel Framework
Quickly Deploying Nest.js Framework
Quickly Deploying Next.js Framework
Quickly Deploying Nuxt.js Framework
Quickly Deploying Django Framework
Use Cases
Overview
Solutions with Tencent Cloud Services
Business Development
TRTC Practices
COS Practices
CKafka Practice
CLS
CLB Practice
MPS
CDN
CDWPG
VOD
SMS
ES
Scheduled Task
Video Processing
Success Stories
Tencent Online Education
Online Video Industry
Tencent Online Education
Best Practice of Tencent IEG Going Global
API Documentation
History
Introduction
API Category
Making API Requests
Other APIs
Namespace APIs
Layer Management APIs
Async Event Management APIs
Trigger APIs
Function APIs
Function and Layer Status Description
Data Types
Error Codes
SDK Documentation
FAQs
General
Web Function
Billing FAQs
Network FAQs
Log FAQs
SCF utility class
Event Handling FAQs
API Gateway Trigger FAQs
Related Agreement
Service Level Agreement
Contact Us
Glossary

Log Description

PDF
Mode fokus
Ukuran font
Terakhir diperbarui: 2025-07-29 14:09:39

Logging

You can use the following statements in the program to output the log:
console.log()
console._stdout.write() (supported for Node.js 8.9 or later)
process.stdout.write() (supported for Node.js 8.9 or later)
For example, you can query the output in the function log by running the following code.
'use strict';
exports.main_handler = async (event, context) => {
console.log("Hello World")
console._stdout.write("Hello World")
process.stdout.write("Hello World")
return event
};

Notes

The Node.js 12.16 and 10.15 runtime environments use console.log to print logs. The platform will encapsulate the log content in the format of "timestamp RequestId log content" and write it to CLS.
Example:
Log print statement: console.log("hello world") Log output: 2021-12-27T03:53:59.192Z a7358cce-489a-4674-8e4e-68665fa2b81d Hello World
The Node.js 8.9 runtime environment uses console.log, console._stdout.write(), or process.stdout.write() to print logs. The platform will encapsulate the log content in the format of "timestamp RequestId log content" and write it to CLS.
Example:
Log print statement: console.log("hello world") Log output: 2021-12-27T03:53:59.192Z a7358cce-489a-4674-8e4e-68665fa2b81d Hello World
The Node.js 6.10 runtime environment uses console.log to print logs. The platform will encapsulate the log content in the format of "timestamp RequestId log content" and write it to CLS.
Example:
Log print statement: console.log("hello world") Log output: 2021-12-27T03:53:59.192Z a7358cce-489a-4674-8e4e-68665fa2b81d Hello World

Log Query

Currently, the function logs can be uploaded to Tencent Cloud SCF. You can complete the configuration as instructed in Log Delivery Configuration. You can search function execution logs on the log query page of the SCF or CLS console. For more information on how to query logs, see Log Search Guide.
Note:
Function logs uploaded to logset and log topic can be both queried with a function configured.

Custom Log Fields

Currently, the content output by simple log print statements in the function code will be recorded in the SCF_Message field when it is delivered to CLS. For descriptions of CLS fields, see Log Delivery Configuration.
Currently, SCF supports adding custom fields to logs that are uploaded to CLS. The custom fields allow you to output business fields and relevant data to logs, and track them using the log search feature of CLS.
Note:
If you need to query the key value of a custom field such as SCF_CustomKey: SCF, add a key-value index to the log topic for SCF log delivery as instructed in Configuring Indexes.
To avoid function log query failures caused by misuse of the index configuration, the default destination topic for SCF log delivery (prefixed with SCF_LogTopic_) does not support modifying the index configuration. You need to set the destination topic to custom delivery first and then update the log topic's index configuration.
After the index configuration is modified for a log topic, it will take effect only for newly written data.

Output

If a function outputs a single-line log in JSON, the log will be parsed and uploaded to CLS in the field:value format. Only top-level field:value pairs where the value is numeric or a string are parsed; other types are ignored.
Run the following codes and check results:
'use strict';
exports.main_handler = async (event, context) => {
console._stdout.write(JSON.stringify({"key1": "test value 1","key2": "test value 2"})+'\\n');
return "hello world"
};
After using the above code to perform a test, you can run the following statement to search in Function Management > Log Query > Advanced Search:


Search for logs After the test is written to CLS, you can find the key1 field in the log query as shown below:



Bantuan dan Dukungan

Apakah halaman ini membantu?

masukan