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
Focus Mode
Font Size
Last updated: 2025-07-29 14:09:39

Log Development

You can use the following statements in the program to output a log:
print
logging module
For example, you can query the output content in the function log by running the following code:
import logging
logger = logging.getLogger()
logger.setLevel(logging.INFO)
logger.addHandler(logging.StreamHandler(sys.stdout))

def main_handler(event, context):
logger.info('got event{}'.format(event))
print("got event{}".format(event))
return 'Hello World!'

Log Query

Currently, all function logs are delivered to CLS. You can configure the function log delivery. For more information, see Log Delivery Configuration. You can query function execution logs on the log query page of SCF or CLS. For more information on the log query method, see Log Search Guide.
Note:
Function logs are delivered to the LogSet log set and LogTopic log topic in CLS, both of which can be queried through the function configuration.

Custom Log Fields

Currently, the string content output by simple print or logger 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.
At present, SCF supports adding custom fields to the content output to CLS. By doing so, you can output business fields and related data content to logs and use the search capability of CLS to query and track them in the execution process.
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 method

If a single-line log output by a function is in JSON format, the JSON content will be parsed into the format of field:value when it is delivered to CLS. Only top-level field:value pairs where the value is numeric or a string are parsed; other types are ignored.
You can run the following code to test:
# -*- coding: utf8 -*-
import json

def main_handler(event, context):
print(json.dumps({"key1": "test value 1","key2": "test value 2"}))
return("Hello World!")


Search method

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 result After the test is written to CLS, you can find the key1 field in the log query as shown below:



Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback