You can store function execution logs to Log Service (SLS), and then perform operations such as debugging, fault analysis, and data analysis based on the logs. This topic describes how to configure projects and Logstores for Function Compute in the Function Compute console and view function execution logs in the SLS console.

Background information

SLS is an end-to-end logging service developed by Alibaba Cloud. To store function logs by using SLS, you must configure projects and Logstores in corresponding services and authorize the services to access SLS. Function logs are stored in Logstores. All function logs of a service are stored in the same Logstore.

Procedure

  1. Log on to the Function Compute console and configure projects and Logstores for services.
    • You can select Bind Log when you create a service. For more information, see Create a service.

      After the service is created, Function Compute creates and binds the corresponding project and Logstore in the background and authorizes you to write function logs to SLS resources.

      Note SLS resources created by Function Compute in the background are billed on a pay-as-you-go basis. For more information, see billing methods.
      enter_name
    • You can configure projects and Logstores when you update services. For more information, see Update a service. Before you configure them, make sure that the corresponding SLS resources have been created. For more information about how to create the SLS resources, see Step 1: Create a project and a Logstore.

      You must set Log Project and Logstore to a created project and a created Logstore in the Log Configs section, and set parameters in the Role Config section to allow Function Compute to write function execution logs to your SLS, as shown in the following figure. For more information, see Permissions.

      config_log_while_update_service
  2. Log on to the SLS console to view logs. For more information, see Step 3: Search and analyze logs.

    In the configured service, create a default function that prints hello world. When the function is executed, the generated logs will be stored in the Logstore. You can view the logs in the SLS console.

    test-logstore

References

You can also use Function Compute Command Line Interface (fcli) to configure SLS resources and view function execution logs. For more information, see Use fcli for the first time.