All Products
Document Center

Log Service:get_logs

Last Updated:Oct 26, 2023

Queries logs in a specified Logstore of a specified project. This command is suitable for scenarios in which you want to query logs in exact match mode. When you use this command, you must prepare a configuration file in the JSON format. This way, you can configure query requests by using the file in a flexible and accurate manner.

Command syntax

aliyunlog log get_logs --request=<value> [--access-id=<value>] [--access-key=<value>] [--sts-token=<value>] [--region-endpoint=<value>] [--client-name=<value>] [--jmes-filter=<value>] [--format-output=<value>] [--decode-output=<value>]

Command parameters

The following table describes the required parameters of this command and the parameters that are specific to this command.







JSON Object



The path to the configuration file. The configuration file contains the parameters that are used to query logs.

Before you run the command, you must create the configuration file. In the configuration file, you must specify a project, Logstore, time range, and query statement.

For more information about the global parameters of this command, see Global parameters.


Query the distribution of the top 3 status codes in a Logstore named logstore-a. Procedure:

  1. Create a file named getlogs.json. Content example:

    "topic": "",
    "logstore": "logstore-a",
    "project": "aliyun-test-project",
    "toTime": "2021-05-28 15:33:00",
    "offset": "0",
    "query": "*|select status,COUNT(*) as pv group by status order by pv desc limit 3",
    "line": "2",
    "fromTime": "2021-05-28 15:18:00",
    "reverse": "true"

    We recommend that you specify a valid search or query statement that can be used to query data in the Simple Log Service console for the query parameter. For more information, see Log search overview and Log analysis overview.

  2. Use the default account to query logs. Command example:

    aliyunlog log get_logs --request="file://./getlogs.json" --format-output=json

    The following result is returned:

        "__source__": "",
        "__time__": "1622186280",
        "pv": "7928",
        "status": "200"
        "__source__": "",
        "__time__": "1622186280",
        "pv": "87",
        "status": "204"
        "__source__": "",
        "__time__": "1622186280",
        "pv": "67",
        "status": "301"

    The query and analysis results show the top 3 statuses and the number of page views for each status.


  • Simple Log Service CLI provides the following commands that can be used to query logs. You can select a command based on your scenario.




    Queries a specified number of logs.


    Queries a large number of logs.

  • If the response that is returned by Log Service contains error information after you call an API operation, the call fails. You can handle errors based on the error codes that are returned when API calls fail. For more information, see Error codes.
  • Alibaba Cloud OpenAPI Explorer provides debugging capabilities, SDKs, examples, and related documents. You can use OpenAPI Explorer to debug Log Service API operations without the need to manually encapsulate or sign requests. For more information, visit OpenAPI Portal.
  • For more information about the API operation that corresponds to this command, see GetLogs.

  • Simple Log Service provides examples on how to call the GetLogs API operation by using Simple Log Service SDK for Java and Simple Log Service SDK for Python. For more information, see Use GetLogs to query logs and Use GetLogs to query logs.