Queries the contextual logs of a specified log.
Operation description
Usage notes
- You can specify a log as the start log. The time range of a contextual query is one day before and one day after the generation time of the start log.
- Host consists of a project name and a Simple Log Service endpoint. You must specify a project in Host.
- An AccessKey pair is created and obtained. For more information, see AccessKey pair.
The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations in Simple Log Service is a high-risk operation. We recommend that you use a Resource Access Management (RAM) user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. Make sure that the RAM user has the management permissions on Simple Log Service resources. For more information, see Create a RAM user and authorize the RAM user to access Simple Log Service.
- The information that is required to query logs is obtained. The information includes the name of the project to which the logs belong, the region of the project, and the name of the Logstore to which the logs belong. For more information, see Manage a project and Manage a Logstore.
- Indexes are configured before you query logs. For more information, see Create indexes.
- The values of the pack_id and pack_meta fields are obtained before you query logs. The fields are internal fields, and you can obtain the values by using the debugging feature of your browser in the Simple Log Service console.
Authentication resources
The following table describes the authorization information that is required for this operation. You can add the information to the Action element of a RAM policy statement to grant a RAM user or a RAM role the permissions to call this operation.
Action | Resource |
---|---|
log:GetLogStoreContextLogs | acs:log:{#regionId}:{#accountId}:project/{#ProjectName}/logstore/{#LogstoreName} |
Debugging
Authorization information
Request syntax
GET /logstores/{logstore}
Request parameters
Parameter | Type | Required | Description | Example |
---|---|---|---|---|
project | string | Yes | The name of the project. | ali-test-project |
logstore | string | Yes | The name of the Logstore. | test-logstore |
type | string | Yes | The type of the data in the Logstore. Set the value to context_log. | context_log |
pack_id | string | Yes | The unique identifier of the log group to which the start log belongs. | 85C897C740352DC6-808 |
pack_meta | string | Yes | The unique context identifier of the start log in the log group. | 2|MTY1NTcwNTUzODY5MTY0MDk1Mg==|3|0 |
back_lines | long | Yes | The number of logs that you want to obtain and are generated before the generation time of the start log. Valid values: | 10 |
forward_lines | long | Yes | The number of logs that you want to obtain and are generated after the generation time of the start log. Valid values: | 10 |
Response parameters
The logs parameter contains log content and the following fields that are formatted in key-value pairs.
Field | Type | Example | Description |
---|---|---|---|
__index_number__ | String | -100 | The position of the log in the context. A negative value indicates that the log is generated before the generation time of the start log. The value 0 indicates that the log is the start log. A positive value indicates that the log is generated after the generation time of the start log. For example, the value -100 indicates that the log is the 100th log before the generation time of the start log. |
__tag__:__pack_id__ | String | 895CEA449A52FE-8c8 | The unique identifier of the log group to which the log belongs. The identifier can be used as the value of the pack_id parameter in the request. |
__pack_meta__ | String | `0 | MTU1OTI4NTExMjg3NTQ2NDU1OA== |
Examples
Sample success responses
JSON
format
{
"total_lines": 201,
"back_lines": 100,
"forward_lines": 100,
"progress": "Complete",
"logs": [
{
"__index_number__": "-100",
"__tag__:__pack_id__": "895CEA449A52FE-8c8",
"__pack_meta__": "0|MTU1OTI4NTExMjg3NTQ2NDU1OA==|4|1"
}
]
}
Error codes
For a list of error codes, visit the Service error codes.