Queries logs.

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 specific parameters of the get_logs command.
Parameter Type Required Example Description
--request JSON Object Yes file://./getlogs.json The path of the configuration file that is used to query logs.
For information about the global parameters of the Log Service command-line interface (CLI), see Global variables.

Examples

Query the distribution of the top 3 status codes in a Logstore named logstore-a.
  1. Create a file named getlogs.json. The following example shows the content of the getlogs.json file:
    {
    "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. Run the following command:
    aliyunlog log get_logs --request="file://./getlogs.json"
    The following output 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 codes of the related API operation. For more information, see Error codes of GetLogs.

API reference

GetLogs