All Products
Search
Document Center

Function Compute:Configure the logging feature

Last Updated:Mar 15, 2026

Function Compute integrates with Simple Log Service. After you configure logging for a function, Function Compute automatically collects logs and delivers them to a specified project and Logstore. You can view single-request logs, instance logs, and function logs in the Function Compute console. You can also run custom searches using the log analysis capabilities in the Simple Log Service console.

Background information

Simple Log Service is a one-stop service for log data. It provides full-stack capabilities such as log collection, storage, query, analysis, visualization, and alerting. To store function logs using Simple Log Service, configure a project and a Logstore for the function and grant the function permissions to access Simple Log Service. After the configuration is complete, function logs are written to the specified Logstore.

Billing

Billing method

Function Compute does not charge extra fees for the logging feature. Simple Log Service charges fees after logs are delivered to it.

  • When the billing method for the Logstore is pay-by-feature, Simple Log Service charges you for storage, read traffic, number of requests, data transformation, and data shipping after logs are pushed to it. For more information, see Billing items for the pay-by-feature billing method.

  • When the billing method for the Logstore is pay-by-ingested-data, Simple Log Service charges you for metrics such as the amount of raw data ingested after logs are pushed to it. For more information, see Billing items for the pay-by-ingested-data billing method.

To change the billing method for a Logstore, see Manage a Logstore.

Stop billing

To stop billing, first disable the logging feature in the Function Compute console. Then, go to the Simple Log Service console to delete the Logstore or delete the project.

Important

Deleting a Simple Log Service project or Logstore is irreversible. After deletion, logs can no longer be delivered to Simple Log Service, and existing data is deleted. Back up important log data before you perform the deletion.

Enable the logging feature for a function

Configure logging in the Function Compute console

Prerequisites

Procedure

  1. Log on to the Function Compute console. In the left-side navigation pane, click Functions.

  2. In the top navigation bar, select a region. On the Functions page, click the function that you want to manage.

  3. On the function details page, click the Configuration tab. Click Modify next to Advanced Settings. In the Advanced Settings panel, find the Logs option, configure the logging parameters, and then click Deploy.

    image

    Note
    • When you create a function, the logging feature is enabled by default, and the system automatically selects a Log Service Project that starts with serverless-<region_id> and the default Logstore.

    • The console automatically enables Log Rotation Rules, Request-level Metrics, and Instance-level Metrics, and creates all the indexes required for log queries.

    Configuration Item

    Required

    Description

    Logging Feature

    Yes

    Specifies whether to enable Simple Log Service. Valid values:

    • Enable: After you enable this feature, Function Compute imports logs to your project. You can query and retrieve logs in the Function Compute console and the Simple Log Service console to track and locate issues.

    • Disable: If you disable the logging feature, function logs are not persisted. You cannot track and locate issues.

    Configuration Mode

    Yes

    Select Automatic Configuration or Custom Configuration. If you select Custom Configuration, Log Service Project and Logstore are required.

    Log Service Project

    Yes

    The destination project where function invocation logs are stored.

    Logstore

    Yes

    The destination Logstore where function invocation logs are stored.

    Log Rotation Rules

    No

    Specifies whether to enable a log segmentation rule. Valid values:

    • Enable: If you enable this feature, Function Compute splits logs based on the segmentation rule and writes the log segments to Simple Log Service one by one.

      The default segmentation rule is ^.{0,2}\d{4}-\d{2}-\d{2}. This rule matches dates in the xxxx-xx-xx format, where x represents a digit. Logs are split based on whether a line starts with a date. For example, if a log line starts with 2023-10-10, it is considered the first line of a log segment. This line and the subsequent lines that do not start with a date are written to Simple Log Service as a single log entry.

    • Disable: If you disable this feature, logs are split using \n by default.

    Request-level Metrics

    No

    Specifies whether to import logs of request-level metrics to the Logstore. Enabling this feature is strongly recommended.

    Valid values:

    • Enable: After you enable this feature, metrics for each function invocation, such as the function execution time, memory usage, execution errors, cold starts, and the time taken for each cold start step, are delivered to the Logstore that you selected. Based on these metrics, Function Compute can display a list of requests in the invocation logs. You can also filter requests based on these metrics, such as filtering all error requests or requests that involve cold starts.

    • Disable: You cannot view the details of request executions.

    Instance-level Metrics

    No

    Specifies whether to enable instance-level metrics. Valid values:

    • Enable: After you enable this feature, instance-level metrics of the function are delivered to the Logstore that you selected. You can view performance metrics at the function instance level, such as the CPU, memory, and network I/O metrics of an instance. Function Compute provides instance-level observability based on instance-level metrics, offering an end-to-end monitoring and troubleshooting path for function instances. For more information, see Instance-level metrics.

    • Disable: You cannot view the details of instance metrics.

Configure logging using Serverless Devs

Prerequisites

Install and configure Serverless Devs.

Procedure

  1. Create a code directory with the following structure.

    .
    ├── code
    │   └── index.js
    └── s.yaml

    The following is a sample s.yaml file.

    In this example, the logConfig field configures the logging feature. Change the values of logstore and project to your actual Logstore and project. You can also set logConfig to auto to automatically create a project and a Logstore.

    edition: 3.0.0
    name: hello-world-app
    access: "default"
    vars: # Global variables
      region: "cn-hangzhou"
    
    resources:
      hello_world:
        component: fc3 # Component name
        props:
          region: ${vars.region}             
          functionName: "start-nodejs-****"
          description: 'hello world by serverless devs'
          runtime: "nodejs16"
          code: ./code
          handler: index.handler
          memorySize: 128
          timeout: 30
          logConfig: # Change the values of logstore and project to your actual Logstore and project. You can also set logConfig to auto to automatically create a project and a Logstore.
            enableInstanceMetrics: true  # Enable instance-level metrics
            enableRequestMetrics:  true  # Enable request-level metrics
            logBeginRule: DefaultRegex   # Log segmentation rule
            logstore: 'your-logstore'    # The name of the Logstore. The Logstore must be created in advance.
            project: 'your-project'      # The name of the project. The project must be created in advance.
  2. Run the following command to deploy the application.

    sudo s deploy -y

    After the command runs successfully, log on to the Function Compute console to view the deployed function and verify that the logging feature is enabled.

Disable the logging feature

Note

After you disable the logging feature, function execution logs are no longer collected or stored. This may affect troubleshooting and performance analysis. Proceed with caution.

  1. Log on to the Function Compute console. In the left-side navigation pane, click Functions.

  2. In the top navigation bar, select a region. On the Functions page, click the function that you want to manage.

  3. On the function details page, click the Configuration tab. Click Modify next to Advanced Settings. In the Advanced Settings panel, find the Logs option, turn off the Logging Feature switch, and then click Deploy.

View invocation logs

On the function details page, click the Logs tab to query the invocation records of the current function.

Note

On the function details page, click the Version Management or Alias Management tab. Select and click the function version or alias that you want to query to go to its details page. Then, click the Logs tab to query the corresponding logs.

You can view function invocation log content on the Invocation Requests tab or the Search by Keyword tab. The differences are as follows:

  • Invocation Requests

    This tab lists information such as the end time of the function invocation, request ID, invocation result, instance ID, and function version or alias.

    • Click a Request ID to view request details and log details.

    • Click an Instance ID to view the instance's metric usage, such as CPU usage, memory usage, and network traffic.

    • In the Actions column, click Request Logs to view log details, or click Actions column's Advanced Logs to go to the Simple Log Service console to query and analyze logs.

  • Search by Keyword

    This tab lists information such as the function invocation time, log content, and function version or alias. In the Actions column, click Log Context to retrieve several contextual log entries for this log, or click Logstore in the Actions column to go to the Simple Log Service console to query and analyze logs.

    Enter a keyword in the search box to query the log information you need. For example, to search for logs containing the text hello world, enter the keyword hello world in the search box. The search results include all log lines that contain this keyword. For more information about keyword query syntax, see Query and analysis syntax.

References

Configure logging for a function by calling the SDK or API. For more information, see Create a function.