All Products
Search
Document Center

:GetContextLogs

Last Updated:Apr 25, 2024

Queries the contextual logs of a specified log.

Operation description

  • 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.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer.

Authorization information

The following table shows the authorization information corresponding to the API. The authorization information can be used in the Action policy element to grant a RAM user or RAM role the permissions to call this API operation. Description:

  • Operation: the value that you can use in the Action element to specify the operation on a resource.
  • Access level: the access level of each operation. The levels are read, write, and list.
  • Resource type: the type of the resource on which you can authorize the RAM user or the RAM role to perform the operation. Take note of the following items:
    • The required resource types are displayed in bold characters.
    • If the permissions cannot be granted at the resource level, All Resources is used in the Resource type column of the operation.
  • Condition Key: the condition key that is defined by the cloud service.
  • Associated operation: other operations that the RAM user or the RAM role must have permissions to perform to complete the operation. To complete the operation, the RAM user or the RAM role must have the permissions to perform the associated operations.
OperationAccess levelResource typeCondition keyAssociated operation
log:GetLogStoreContextLogsRead
  • LogStore
    acs:log:{#regionId}:{#accountId}:project/{#ProjectName}/logstore/{#LogstoreName}
  • log:TLSVersion
none

Request syntax

GET /logstores/{logstore}

Request parameters

ParameterTypeRequiredDescriptionExample
projectstringYes

The name of the project.

ali-test-project
logstorestringYes

The name of the Logstore.

test-logstore
typestringYes

The type of the data in the Logstore. Set the value to context_log.

context_log
pack_idstringYes

The unique identifier of the log group to which the start log belongs.

85C897C740352DC6-808
pack_metastringYes

The unique context identifier of the start log in the log group.

2|MTY1NTcwNTUzODY5MTY0MDk1Mg==|3|0
back_lineslongYes

The number of logs that you want to obtain and are generated before the generation time of the start log. Valid values: (0,100].

10
forward_lineslongYes

The number of logs that you want to obtain and are generated after the generation time of the start log. Valid values: (0,100].

10

Response parameters

ParameterTypeDescriptionExample
object

Schema of Response

total_lineslong

The total number of logs that are returned. The logs include the start log that is specified in the request.

201
back_lineslong

The number of logs that are generated before the generation time of the start log.

100
forward_lineslong

The number of logs that are generated after the generation time of the start log.

100
progressstring

Indicates whether the query and analysis results are complete. Valid values:

  • Complete: The query is successful, and the complete query and analysis results are returned.
  • Incomplete: The query is successful, but the query and analysis results are incomplete. To obtain the complete results, you must repeat the request.
Complete
logsobject []

The logs that are returned.

object

The logs that are returned. The logs are arranged in contextual order. If no contextual logs are found based on the specified start log, this parameter is empty.

{ "__index_number__": "-100", "__tag__:__pack_id__": "895CEA449A52FE-8c8", "__pack_meta__": "0|MTU1OTI4NTExMjg3NTQ2NDU1OA==|4|1" }

The logs parameter contains log content and the following fields that are formatted in key-value pairs.

FieldTypeExampleDescription
__index_number__String-100The 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__String895CEA449A52FE-8c8The 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__String0|MTU1OTI4NTExMjg3NTQ2NDU1OA==|4|1The unique context identifier of the log in the log group. The identifier can be used as the value of the pack_meta parameter in the request.

Examples

Sample success responses

JSONformat

{
  "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.