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.
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. 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.
Examples
Query the distribution of the top 3 status codes in a Logstore named logstore-a. Procedure:
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.
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:
{ "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 and analysis results show the top 3 statuses and the number of page views for each status.
References
Simple Log Service CLI provides the following commands that can be used to query logs. You can select a command based on your scenario.
Command
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.