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.
- Log Service console
- Function Compute Command Line Interface (fcli)
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.
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.
- Click Create Project in the Log Service console.
- 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.
- Create a Logstore in the project that you created.
- After a Logstore is created, go to the details page of the Logstore and enable the index function in the upper-right corner.
- You have created a project and a Logstore.
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.
- For more information about service permissions, see User permissions.
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.
Download and configure fcli. For more information about fcli, see fcli.
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:
~ fcli shell
Welcome to the function compute world. Have fun!
>>> mkl -p test-log-project -s test-log-store
Note: you have to pay at least 0.04 RMB/day for the log store resource. For the detail billing info please refer to:
Do you want to create the log store? [y/n]
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.
>>> grant serviceName
Please input the role name: # Specify a name for the role. A new role is created.
Please input the policy name: # Specify a name for the permission. A new permission is created.
Permission grant scenarios:
1. Allow FC write function logs to your log store. # Select a permission
2. Allow FC copy code from your OSS location.
Please input your choice [1-2]:
Please input the log project: test-log-project
Please input the log store: test-log-store
logs command to view logs
: specify the maximum number of returned log entries (Default value: 1000).
: 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).
: 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.
: 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.
: specify a number N to return the last N number of log entries.
# Under the directory of the service that use the functions,
# the first 1,000 log entries of the current day are displayed by default.
>>> logs myFunction
# Display the logs generated within one minute. Up to 5,000 log entries can be displayed.
>>> logs -d 60 -c 5000 myFunction
# Display the last 100 log entries.
>>> logs -t -c 100 myFunction
# Display the function logs generated from 2018-01-22T18:00:00Z to 2018-01-22T19:00:00Z
>>> logs -s 2018-01-22T18:00:00Z -e 2018-01-22T19:00:00Z myFunction