List all Logstores in a Project

Updated at:

Lists all Logstores in a specified project by calling the ListLogStores operation.

Prerequisites

Parameters

def list_logstores(self, request):

Request parameters

Parameter

Type

Required

Description

request

ListLogstoresRequest

Yes

The request object that specifies the query criteria for listing Logstores.

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

Response parameters

For more information about the response parameters, see ListLogStores.

Sample code

import os
from aliyun.log import LogClient
from aliyun.log import ListLogstoresRequest

# Get 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 Log Service.
endpoint = "cn-hangzhou.log.aliyuncs.com"

client = LogClient(endpoint, access_key_id, access_key_secret)


def main():
    # The names of the Projects.
    project_names = ["project-1", "project-2"]

    for project_name in project_names:
        try:
            request = ListLogstoresRequest(project_name)
            res = client.list_logstores(request)
            print(f"Logstores for project '{project_name}':")
            res.log_print()  # Print details of the returned Logstores.
        except Exception as e:
            print(f"Error occurred while fetching logstores for project '{project_name}': {str(e)}")


if __name__ == "__main__":
    main()

Sample response

Logstores for project 'project-1':
ListLogstoresResponse:
headers: {'Server': 'AliyunSLS', 'Content-Type': 'application/json', 'Content-Length': '68', 'Connection': 'keep-alive', 'Access-Control-Allow-Origin': '*', 'Date': 'Thu, 24 Oct 2024 07:10:23 GMT', 'x-log-time': '1729753823', 'x-log-requestid': '6719F2DF101DAD9CB838****'}
count: 3
total: 3
logstores: ['logstore-1', 'logstore-2', 'logstore-3']
Logstores for project 'project-2':
ListLogstoresResponse:
headers: {'Server': 'AliyunSLS', 'Content-Type': 'application/json', 'Content-Length': '36', 'Connection': 'keep-alive', 'Access-Control-Allow-Origin': '*', 'Date': 'Thu, 24 Oct 2024 07:10:23 GMT', 'x-log-time': '1729753823', 'x-log-requestid': '6719F2DFBC740FFE34A0****'}
count: 0
total: 0
logstores: []