All Products
Search
Document Center

Simple Log Service:get_log

Last Updated:Jun 02, 2026

Queries a specified number of logs from a Logstore.

Request syntax

aliyunlog log get_log --project=<value> --logstore=<value> --from_time=<value> --to_time=<value> [--topic=<value>] [--query=<value>] [--reverse=<value>] [--offset=<value>] [--size=<value>] [--power_sql=<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>] [--profile=<value>]

Request parameters

The following table lists the command-specific parameters.

Parameter name

Data type

Required

Example value

Description

--project

String

Yes

aliyun-test-project

The project name.

--logstore

String

Yes

logstore-a

The Logstore name.

--from_time

String

Yes

2021-05-28 15:33:00+8:00

Start of the query time range. Specify as a UNIX timestamp or in the "%Y-%m-%d %H:%M:%S<time_zone>" format. Example: "2018-01-02 12:12:10+8:00".

--to_time

String

Yes

2021-05-28 15:40:00+8:00

End of the query time range. Specify as a UNIX timestamp or in the "%Y-%m-%d %H:%M:%S<time_zone>" format. Example: "2018-01-02 12:12:10+8:00".

--topic

String

No

""

The log topic. Defaults to an empty string (""). Topic.

--query

String

No

level:Information|select event_id as Key1,COUNT(*) as Key2 group by Key1

The query or analytic statement. Query and analysis overview.

Adding set session parallel_sql=true; to the analytic statement enables Dedicated SQL. Example: * | set session parallel_sql=true; select count(*) as pv.

Note

If the query parameter contains an analytic statement, set size and offset to 0 and use the LIMIT clause for pagination. Paginate query and analysis results.

--reverse

Boolean

No

true

Whether to return logs in descending order of timestamp (accurate to the minute).

  • true: Descending order.

  • false (default): Ascending order.

Important
  • This parameter applies only to query statements, not analytic statements.

  • For analytic statements, use the ORDER BY clause to control sort order. Default: ascending (asc).

--offset

Integer

No

0

The row to start the query from. Valid only for query statements. Default: 0.

--size

Integer

No

10

Maximum number of logs to return. Valid only for query statements. Value range: 0 to 100. Default: 100.

--power_sql

Boolean

No

false

Whether to use Dedicated SQL. High-performance and fully accurate query and analysis (Dedicated SQL).

  • true: Uses Dedicated SQL.

  • false (default): Uses Standard SQL.

You can enable Dedicated SQL by setting this parameter to true or by adding the directive in the query parameter.

This command also supports Global parameters.

Examples

  • Request example

    Query the top 20 POST request statuses using the default account.

    aliyunlog log get_log --project="aliyun-test-project" --logstore="logstore-a" --from_time="2021-05-28 15:33:00+8:00" --to_time="2021-05-28 15:40:00+8:00" --query="request_method:POST | select status,COUNT(*) as pv group by status order by pv desc limit 20" --format-output=json
  • Response example

    {
      "data": [
        {
          "__source__": "",
          "__time__": "1719382500",
          "pv": "17",
          "status": "200"
        },
        {
          "__source__": "",
          "__time__": "1719382500",
          "pv": "3",
          "status": "500"
        }
      ],
      "meta": {
        "aggQuery": "select status,COUNT(*) as pv group by status order by pv desc limit 20",
        "columnTypes": [
          "long",
          "long"
        ],
        "count": 2,
        "cpuSec": 0.025,
        "elapsedMillisecond": 0,
        "hasSQL": true,
        "insertedSQL": "1,29, from \"gs-api\" ",
        "isAccurate": true,
        "keys": [
          "status",
          "pv"
        ],
        "processedBytes": 226,
        "processedRows": 20,
        "progress": "Complete",
        "telementryType": "logging",
        "telemetryType": "logging",
        "terms": [
          {
            "key": "",
            "term": "*"
          }
        ],
        "whereQuery": "*"
      }
    }

Related commands

Command

Scenario

get_logs

Performs a term query on logs using a JSON configuration file.

get_log_all

Queries a large volume of log data.