Queries logs in a LogStore. Accepts a JSON request file that specifies the project, LogStore, time range, and query and analytic statements.
Command format
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>]
Parameters
Command-specific parameters:
|
Parameter Name |
Data type |
Required |
Example |
Description |
|
--request |
JSON Object |
Yes |
file://./getlogs.json |
Path to the JSON configuration file. Create this file before running the command. Specify the project, LogStore, time range, and query and analytic statements. |
This command also supports Global parameters.
Examples
Query the top three status codes by count in logstore-a.
-
Create a file named getlogs.json with the following content:
{ "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" }The `query` parameter accepts any valid query or analytic statement. Query overview. Query and analysis overview.
-
Run the command with the default account:
aliyunlog log get_logs --request="file://./getlogs.json" --format-output=jsonSample response:
{ "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, "cpuCores": 11, "cpuSec": 0.024, "elapsedMillisecond": 38, "hasSQL": true, "insertedSQL": "1,29, from \"logstore-a\" ", "isAccurate": true, "keys": [ "status", "pv" ], "powerSql": false, "processedBytes": 226, "processedRows": 20, "progress": "Complete", "telementryType": "logging", "telemetryType": "logging", "terms": [ { "key": "", "term": "*" } ], "whereQuery": "*" } }The query returns the top three status codes and their distribution.
References
-
Related log query commands:
Command
Scenarios
Query a specified number of logs.
Query a large volume of log data.
In addition to its native SDK, SLS also supports the common Alibaba Cloud SDKs. For more information, see Simple Log Service_SDK Center_Alibaba Cloud OpenAPI Explorer.
-
API reference: GetLogs.
-
GetLogs SDK examples (Java and Python): Use the GetLogs operation to query logs and Use the GetLogs operation to query logs.