edit-icon download-icon

Use Log Service to view API call logs

Last Updated: Mar 29, 2018

The API Gateway and Log Service are seamlessly integrated. The Log Service enables you to view real-time log information, download logs, and analyze logs from multiple dimensions. You can also send logs to OSS or MaxCompute.

Business sketch diagram

  • For details about more Log Service functions, see Log Service help.

  • You can use the Log Service free-of-charge for the first 500 MB of log data every month. For the prices of other items, see Log Service pricing.

1 Function overview

1.1 Online log search

You can specify any keyword in logs to complete an exact or fuzzy log search quickly. The search results can be used for fault location or log statistics collection.

1.2 Detailed API call logs

You can obtain detailed API call information based on the following log items:

Log item Description
apiGroupUid API group ID
apiGroupName API group name
apiUid API ID
apiName API name
apiStageUid API environment ID
apiStageName API environment name
httpMethod Called HTTP method
path Request path
domain Called domain name
statusCode HttpStatusCode
errorMessage Error message
appId Caller application ID
appName Caller application name
clientIp IP address of the caller client
exception Specific error message returned from the backend
providerAliUid API provider account ID
region Region name, such as cn-hangzhou
requestHandleTime Request time (UTC)
requestId Request ID, globally unique
requestSize Request size, unit: byte
responseSize Returned data size, unit: byte
serviceLatency Backend latency, unit: millisecond

1.3 Custom analysis charts

You can define statistical charts of any log items to obtain statistical data required for business operation.

1.4 Preset analysis reports

The API Gateway provides predefined statistical charts (global) for you to use directly. These statistical charts show log items including the request size, success rate, error rate, latency, number of applications that call an API, error statistics, top groups, top APIs, and top latencies.

2 Use the Log Service to view API logs

2.1 Configure the Log Service

Before using this function, make sure that you have subscribed to the log service and created a project and a logstore. Click here to create a project and logstore.

You can configure the Log Service on the API Gateway console or Log Service console.

2.1.1 Configure the Log Service on the API Gateway console

1) Open API Gateway Console and choose “Publish APIs” > “Log Manage” and select the region of your service. In the following figure, China East 1 is used as an example.

Create log configuration

2) Click “Create Log Config” to display the log configuration page.

Log configuration

3) Select the project or logstore where the log service is required. If no options are available, click “Authorize Log Service Log Write Operation”, and then grant the authority to access your cloud resources.

Authorization

4) After you confirm the authorization, the API Gateway is successfully associated with the log service.

5) Enable the indexing function to complete the configuration.

2.1.2 Configure the log service on the Log Service console

For details, see Access logs of API Gateway.

After the configuration is complete, your API calls can be recorded in the logstore for the log service.

2.2 View logs

Open API Gateway console and choose “Publish APIs” > “Log Manage” > “Access Log” to go to the log console. Search for call logs online according to Query syntax, as shown in the following figure.

View logs

You can also log on to the Log Service console to view logs. For details, see Query logs.

2.3 View predefined reports

Predefined reports are statistical reports preset on the API Gateway to facilitate log statistics collection. Open API Gateway console and choose “Publish APIs” > “Log Manage” > “Access Log” to view the predefined reports. You can also view these predefined logs on the Log Service console.

Log

2.4 Custom query reports

You can define query reports to meet your own business requirements. For details, see Dashboard.

3 Maintain logs

Open API Gateway Console and choose “Publish APIs” > “Log Manage” to modify or delete log configuration.

  • Modify Config: Change the project or logstore for the log service. Then API call logs are written in the new logstore, but historical logs are still saved in the original logstore and not migrated to the new logstore.
  • Delete Config: Delete the mapping between the API Gateway and log service. The API call logs are no longer synchronized to the log service, but the historical logs in the logstore are not deleted.
Thank you! We've received your feedback.