All Products
Search
Document Center

Logs

Last Updated: Jun 19, 2019

Function Compute stores function logs in Log Service. You can use the function logs stored in Log Service to perform operations such as debugging, fault analysis, and data analysis.This topic describes how to use the Log Service console or fcli to configure a Logstore for a service and view logs in the Logstore.

The Log Service console is not optimized to view logs. We recommend that you use the console to configure a Logstore for a service, then use fcli to view the function logs in the configured Logstore.

To store function logs in Log Service, you must configure a project and a Logstore for the service that uses the functions, and authorize the service to access Log Service. Function logs for a service are stored in the configured Logstore. All the function logs of this service will be stored in the same Logstore.

Log Service console

Use the Log Service console to configure a Logstore for a service

Create a project and a Logstore

Before you configure a Logstore for a service, you must have created a project and a Logstore.If you have not created a project and a Logstore, you must create a project and a Logstore in the Log Service console. The following steps describe how to create a project and a Logstore.

  1. Click Create Project in the Log Service console.
  2. Specify Project Name and Region. The name of each project in Log Service must be globally unique. After you create a project, you cannot change the name and region of the project.
  3. Create a Logstore in the project that you created.
  4. After a Logstore is created, go to the details page of the Logstore and enable the index function in the upper-right corner.
  5. You have created a project and a Logstore.

create-logproject-1create-logproject-2create-logproject-3create-logproject-4create-logproject-5create-logproject-6

Configure a project and a Logstore for a service

To use Log Service to view function logs, you must:

  • Configure a project and Logstore for the service that uses the functions. All the function logs of this service will be stored in the same Logstore.
    • You can configure a project and a Logstore when you create or update a service.
    • For more information about how to create and update a service, see Service operation.
  • Grant the service permissions to access Log Service.

config-service

Use the Log Service console to view logs

In the configured service, create a default function that prints hello world and execute it. Verify if the function logs are stored in Logstore.When a function is executed, the generated logs will be stored in the Logstore. You can use the Log Service console to view the logs in the Logstore.

view-logs

fcli

Download and configure fcli. For more information about fcli, see fcli.

Use fcli to configure a Logstore for a service

Create a project and a Logstore

After you run the fcli shell command to enter the interactive mode, you can run the mkl -p log-project -s log-store command to create a project and a Logstore. Replace the log-project and log-store fields in this command fields with the names of your new project and Logstore.The sample commands are as follows:

  1. ~ fcli shell
  2. Welcome to the function compute world. Have fun!
  3. >>> mkl -p test-log-project -s test-log-store
  4. Note: you have to pay at least 0.04 RMB/day for the log store resource. For the detail billing info please refer to:
  5. https://www.aliyun.com/price/product#/sls/detail
  6. Do you want to create the log store? [y/n]
  7. y

Note: Log Service charges resource reservation fees, which means you are charged at least RMB 0.04/day even if no logs are written. For the billing details, see Billing method.

Configure a project and a Logstore for a service

  1. >>> grant serviceName
  2. Please input the role name: # Specify a name for the role. A new role is created.
  3. fc-logs-role
  4. Please input the policy name: # Specify a name for the permission. A new permission is created.
  5. fc-logs-policy
  6. Permission grant scenarios:
  7. 1. Allow FC write function logs to your log store. # Select a permission
  8. 2. Allow FC copy code from your OSS location.
  9. Please input your choice [1-2]:
  10. 1
  11. Please input the log project: test-log-project
  12. Please input the log store: test-log-store
  13. ...grant success

Use fcli to view logs

Use the logs command to view logs

  • -c -count : specify the maximum number of returned log entries (Default value: 1000).
  • -d -duration : specify a period of time to return the function logs generated in the period specified before the current time. Unit: seconds. Default value: 86400 (24 hours).
  • -e -end : specify a point in time to return logs generated before this point in time. Specify this parameter in the RFC3339 format. The time must be in UTC, for example, 2017-01-01T01:02:03Z.
  • -s -start : specify a point in time to return logs generated after this point in time. Specify this parameter in the RFC3339 format. The time must be in UTC, for example, 2017-01-01T01:02:03Z.
  • -t -tail : specify a number N to return the last N number of log entries.
  1. # Under the directory of the service that use the functions,
  2. # the first 1,000 log entries of the current day are displayed by default.
  3. >>> logs myFunction
  4. # Display the logs generated within one minute. Up to 5,000 log entries can be displayed.
  5. >>> logs -d 60 -c 5000 myFunction
  6. # Display the last 100 log entries.
  7. >>> logs -t -c 100 myFunction
  8. # Display the function logs generated from 2018-01-22T18:00:00Z to 2018-01-22T19:00:00Z
  9. >>> logs -s 2018-01-22T18:00:00Z -e 2018-01-22T19:00:00Z myFunction