Query a cursor by time
Use the GetCursor operation to retrieve the cursor that corresponds to a specific point in time.
Prerequisites
-
Simple Log Service is activated. For more information, see Activate Simple Log Service.
-
The Simple Log Service SDK for Python is initialized. For more information, see Initialize Simple Log Service SDK for Python.
Parameters
def get_cursor(self, project_name, logstore_name, shard_id, start_time):
Request parameters
|
Name |
Type |
Required |
Description |
|
project_name |
String |
Yes |
The name of the project. The project in Simple Log Service is used to isolate the resources of different users and control access to specific resources. See Manage projects. |
|
logstore_name |
String |
Yes |
The name of the logstore. The logstore in Simple Log Service is used to collect, store, and query logs. See Manage Logstores. |
|
shard_id |
int |
Yes |
The ID of the shard in the logstore. |
|
start_time |
String |
Yes |
A point in time. The value can be a UNIX timestamp or the string |
Response parameters
For details about response parameters, see Query a cursor by time.
Sample code
from aliyun.log import LogClient
import os
# This example gets the AccessKey ID and AccessKey secret from environment variables.
access_key_id = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID', '')
access_key_secret = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET', '')
# The endpoint for Simple Log Service.
endpoint = "cn-hangzhou.log.aliyuncs.com"
client = LogClient(endpoint, access_key_id, access_key_secret)
project_name = "proj-test-1"
logstore_name = "logstore-1"
shard_id = 1
start_time = 1727605800
def main():
# Get the cursor based on the specified time.
res = client.get_cursor(project_name, logstore_name, shard_id, start_time)
res.log_print()
if __name__ == '__main__':
main()
Sample response
GetCursorResponse
headers: {'Server': 'AliyunSLS', 'Content-Type': 'application/json', 'Content-Length': '41', 'Connection': 'keep-alive', 'Access-Control-Allow-Origin': '*', 'Date': 'Tue, 15 Oct 2024 06:59:07 GMT', 'x-log-time': '1728975547', 'x-log-requestid': '670E12BBB5C6B8FF265C****'}
cursor: MTcyODYwOTY****DcwODA5MA==
Process finished with exit code 0
References
-
APIs for querying log data:
-
More sample code is available in the Alibaba Cloud Simple Log Service SDK for Python GitHub repository.