Testing, Logging, and Monitoring
This document details how to use the testing, logging, and monitoring features provided by CloudBase to help developers efficiently debug and monitor the operational status of Cloud Functions.
Prerequisites
Before starting to test and monitor cloud functions, ensure that:
- You have created a Tencent Cloud development environment
- You have deployed at least one cloud function
- Have appropriate access permissions
Cloud Function Testing
Cloud Development provides multiple cloud function testing methods, supporting online debugging and local testing, to help developers debug code more conveniently.
- CloudBase Console
- WeChat Developer Tools
Console Testing
The CloudBase console enables you to quickly test cloud function execution.
Test Steps
- In the corresponding cloud function management panel of the console, click the "Test" button to open the test pop-up window.
- Select a testing template or customize test parameters
- Click "Run" to execute the test
- View execution results and log output

Test Parameter Configuration
Use template parameters
- Click the "Submit Method" dropdown menu and select the template method for the test function.
- Template parameters are passed to the function as the
eventparameter during testing.
Custom Parameters Enter JSON-formatted test data in the test parameter editor:
{
"name": "test",
"data": {
"key": "value",
"number": 123
}
}
Local Debugging Tool
Besides the visual test feature, you can also use the command-line tool scf-cli for local debugging.
# Install scf-cli
npm install -g scf-cli
# Local Function Debugging
scf local invoke --template template.yaml --event event.json
WeChat Developer Tools Testing
You can directly test cloud functions in the WeChat Developer Tools.
Test Steps
- In the corresponding cloud function management panel of the console, click "Cloud Test" to open the test pop-up window.
- Configure test parameters
- Click "Run" to execute the test
- View execution results

Parameter Configuration Instructions
- Submit Method: Select the template method for the test function. Currently supports the
Hello Worldevent template. - Test Parameters: Enter JSON-formatted test parameters in the editor
- Running Results: After execution is completed, the results will be displayed in the "Run Test" section.
Local Debugging Support
WeChat Developer Tools also support using scf-cli for local rapid debugging.
Log Viewing
CloudBase provides a comprehensive logging system to help developers quickly locate and resolve issues.
Logging Features
- Real-time Logs: Support real-time viewing of function execution logs
- Structured Display: Log information is displayed in a structured manner, facilitating analysis.
- Multi-dimensional Filtering: Supports filtering logs by time, status, and other criteria
- Details: Contains detailed information such as request ID, execution time, memory usage, etc.
- CloudBase Console
- WeChat Developer Tools
View Console Logs
- Log in to the CloudBase console
- Go to the corresponding cloud function management page
- Click the Logs tab
- Select the time range to view logs

Log Information Description
Each log record contains the following information:
- Timestamp: The specific time of function execution
- Request ID: The unique identifier for a function invocation
- Execution Status: Success or failure status
- Execution Duration: Function execution time
- Memory Usage: Memory consumption during function runtime
- Log Content: The content output by console.log and similar statements in the function
WeChat Developer Tools Logs
View cloud function logs in the WeChat Developer Tools:
- Open the WeChat Developer Tools
- Go to the CloudBase console
- Select the corresponding cloud function
- Click "Logs" to view execution records

Logs Best Practices
Structured Logging
Use a structured logging approach in your function code:
exports.main = async (event, context) => {
const requestId = context.requestId;
// Log the request start
console.log(JSON.stringify({
level: 'INFO',
requestId,
message: message: 'Function execution started',
timestamp: new Date().toISOString(),
event: event
}));
try {
//Business logic.
const result = await processData(event);
// Log the successful result
console.log(JSON.stringify({
level: 'INFO',
requestId,
message: message: 'Function executed successfully',
result: result
}));
return result;
} catch (error) {
// Log error information
console.error(JSON.stringify({
level: 'ERROR',
requestId,
message: message: 'Function execution failed',
error: {
message: error.message,
stack: error.stack
}
}));
throw error;
}
};
Log Level Usage
Proper use of different log levels:
// Info
console.log('General log information');
// Important information to record
console.info('Important information level log');
// Warning information
console.warn('Warning level log');
// Error message.
console.error('Error level log');
- Avoid logging sensitive information (such as passwords, keys, etc.)
- Properly control the log output volume to avoid generating excessive logs
- Use structured log formats to facilitate subsequent analysis and processing
Monitoring Data
Cloud Development provides comprehensive monitoring metrics to help developers understand the operational status and performance of cloud functions.
Monitoring Metrics
Cloud function monitoring includes the following core metrics:
- Invocations: total number of function calls
- Runtime: average and maximum execution time of the function
- Errors: number of failed function executions
- Success rate: percentage of successful function executions
- Memory Usage: Memory consumption during function runtime
- Concurrency: number of concurrent function instances
- CloudBase Console
- WeChat Developer Tools
View Console Monitoring
- Log in to the CloudBase console
- Go to the corresponding cloud function management page
- Click the Monitoring tab
- Select the time range to view monitoring data
- Click 'Export Data' to export monitoring data.

Monitoring Features
- Multiple Time Dimensions: Supports viewing monitoring data for different time ranges.
- Chart Display: Intuitive charts display trends of various metrics.
- Data Export: Supports exporting monitoring data for offline analysis
- Real-time Updates: Monitoring data is updated in real time to reflect the latest status.
WeChat Developer Tools Monitoring
View cloud function monitoring data in the WeChat Developer Tools:
- Open the WeChat Developer Tools
- Go to the CloudBase console
- Select the corresponding cloud function
- Click "Monitoring" to view various metrics
