Queries logs. This command is suitable for scenarios in which you need to query logs in exact match mode. When you use this command, you must prepare a configuration file in the JSON format. You can flexibly and accurately configure query requests by using the file.

Request 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>]

Request parameters

The following table describes the required and unique parameter of this command.
Parameter Type Required Example Description
--request JSON Object Yes file://./getlogs.json The path to the configuration file. The configuration file contains the parameters that are used to query logs.
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"
  2. Use the default account to query logs. Command example:
    aliyunlog log get_logs --request="file://./getlogs.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"

Error codes

If an error message is returned, fix the error based on the error code description of the related API operation. For more information, see Error codes of GetLogs.

API reference


Related commands

Command Description
get_log Queries a specified number of logs.
get_log_all Queries a large number of logs.