Query server-side time through cursor
You can call the GetCursorTime operation to retrieve the server time that corresponds to a cursor.
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.
Parameter description
def get_cursor(self, project_name, logstore_name, shard_id, start_time):
Request parameters
|
Parameter |
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. |
|
cursor |
String |
Yes |
The cursor whose server time you want to query. You can obtain the cursor by calling the GetCursor operation. Note
If the cursor value is less than the |
Response parameters
For more information about the response parameters, see GetCursorTime.
Sample code
from aliyun.log import LogClient
import os
# In this example, the AccessKey ID and AccessKey secret are obtained 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', '')
# Specify a Simple Log Service endpoint.
endpoint = "ap-southeast-1.log.aliyuncs.com"
# Create an instance of the LogClient class
client = LogClient(endpoint, access_key_id, access_key_secret)
project_name = "proj-test-1"
logstore_name = "logstore-1"
shard_id = 1
cursor = "MTcyMTYzO****MTI5MjE0Ng=="
def main():
# Obtain the cursor based on the time.
response = client.get_cursor_time(project_name, logstore_name, shard_id, cursor)
response.log_print()
if __name__ == '__main__':
main()
Sample response
GetCursorTimeResponse
headers: {'Server': 'AliyunSLS', 'Content-Type': 'application/json', 'Content-Length': '26', 'Connection': 'keep-alive', 'Access-Control-Allow-Origin': '*', 'Date': 'Tue, 15 Oct 2024 07:03:31 GMT', 'x-log-time': '1728975811', 'x-log-requestid': '670E13C354D4D7B93256****'}
cursor_time: 1728959278
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.