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

Collecting Business Logs

PDF
フォーカスモード
フォントサイズ
最終更新日: 2025-12-15 10:54:58
This document describes how to create and configure business log collection rules in a container environment through Tencent Cloud Log Service (CLS) to achieve structured log collection and shipping.

Operation Steps

1. Log in to the Serverless Cloud Function (SCF) console. In the left sidebar, choose Data Engineering > Workflow.
2. On the Workflow page, click the service name to go to the workflow details page.
3. Select Log Management and click Add Collection Configuration.
4. In the Create Log Collection Rule pop-up window, specify a custom name for the collection rule.
5. Configure the CLS consumer as follows:
Type: CLS.
Log Region: CLS supports cross-region log shipping. Select the target region for log shipping from the drop-down list.
Logset: Based on the selected region, the system displays logsets you have created. If no existing logset is suitable, you can create a new one in the CLS console. For more information, see Creating a Logset.
Log Topic: Select an existing log topic under the selected logset.
Note:
CLS does not support cross-region log shipping between regions in China and regions outside China.
A single log topic supports only one type of log. Business logs and event logs cannot use the same topic, as this may cause overwriting. Make sure that the selected log topic is not occupied by other collection configurations. If a logset already has 500 log topics, you can no longer create a log topic.
6. Select the collection type and configure the log source. Supported collection types include container standard output and container file path.
Standard Output Logs from a Container
File Logs in a Container
Note:
Standard output logs from a container support only stderr and stdout logs.
The log source supports All Containers and Specified Pod Labels, as shown in the following figure:

All Containers


Namespace Specification Method: Select a namespace specification method. Specify Namespace and Exclude Namespace are supported.
Associated Namespace: Specify the namespace.

Specified Pod Labels


Namespace Specification Method: Select a namespace specification method. Specify Namespace and Exclude Namespace are supported.
Associated Namespace: Specify the namespace.
Pod Label: Add a Pod label to match. By default, all containers matching this label are collected.
The log source supports Specified Pod Labels only.
The collection file path supports both specific paths and wildcard rules. For example, if the container file path is /opt/logs/*.log, you can specify the collection path as /opt/logs and the filename as *.log, as shown in the following figure:

Note:
The container file path cannot be a symbolic link or hard link. Otherwise, the actual path of the soft link will not exist in the collector's container, resulting in a log collection failure.
7. Metadata configuration: support custom metadata or select all metadata.
Field Name
Meaning
container_id
Container ID to which logs belong.
container_name
Container name of the log. If multiple containers under a pod mount the same path, metadata will concatenate the container names with ';'.
image_name
Image name/IP of the container to which logs belong.
namespace
The namespace of the pod to which logs belong.
pod_uid
UID of the pod to which logs belong.
pod_name
Name of the pod to which logs belong.
pod_ip
IP address of the pod to which logs belong.
cluster_id
Cluster ID to which logs belong.
pod_label_{label name}
Label of the pod to which logs belong. For example, if a pod has two labels: app=nginx and env=prod, then the uploaded log will be accompanied by two metadata entries: pod_label_app:nginx and pod_label_env:prod.
When using an existing log topic, you can set suitable indexes as needed. The recommended configuration is pod_name, namespace, container_name, making it easy for log retrieval.
8. Configure the collection policy. You can choose full or incremental.
Full: Full collection collects data from the beginning of the log file.
Incremental: Incremental collection starts collecting from 1M before the end of the file (if the log file is smaller than 1M, it is equivalent to full collection).
Note:
Full collection scenario
Collection rule takes effect with a delay: To ensure all key logs during Pod startup are collected, configure a full collection policy. The full collection policy enables collecting all log data indiscriminately before the rule takes full effect, effectively avoiding log loss.
Incremental collection scenario
Collection path is CBS: When the collection path is on CBS, use the incremental collection strategy to avoid re-collection caused by Pod reconstruction.
Abnormal scenarios
Collection path is CFS: Full collection can lead to re-collection, and multiple Pods may submit identical logs simultaneously, resulting in duplicate billing in CLS. It is advisable not to use CFS for log sources.
9. Click Next and select the log parsing method.
Encoding Mode: UTF-8 and GBK are supported.
Extraction Mode: Multiple types of extraction modes are supported. The details are as follows:
Parsing mode
Description
Documentation
Multi-line full-text
A complete log spans multiple lines and is matched using the first-line regular expression. When a line of log matches the preset regular expression, it is considered to be the beginning of a log. The next line beginning is used as the end identifier of the log, and a default key-value CONTENT is also set. The log time is based on collection time. Support automatically generated regular expression.
JSON
JSON format logs automatically extract the first-level key as the field name and the first-level value as the field value. The entire log will be structured in this way, and each complete log will end with a line break character \\n.
Filter: LogListener only collects logs that meet filter rules. Keys support exact matching, and filtering rules support regular expression matching. For example, you can configure the filter to only collect logs where ErrorCode is set to 404. You can enable the filter and configure rules as needed.
Note:
A log topic currently supports only one collection configuration. Ensure that the logs of all containers that use this log topic can adopt the selected log parsing method. If you create a different collection configuration under the same log topic, the old collection configuration is overwritten.
10. Click Done to complete the creation of the container log collection rule sent to CLS.

ヘルプとサポート

この記事はお役に立ちましたか?

フィードバック