GetLogs
Queries log data in a specified Logstore of a specified project. This operation is deprecated. Use the GetLogsV2 operation instead.
Operation description
Operation description
Simple Log Service allows you to create scheduled SQL tasks. For more information, see Create a scheduled SQL task.
The Host in the request syntax consists of the project name and the Simple Log Service endpoint. You must specify the project in the Host.
An AccessKey pair is created and obtained. For more information, see AccessKey pair.
An Alibaba Cloud account has access permissions to invoke all API operations. Using the AccessKey pair of an Alibaba Cloud account poses high risks. We strongly recommend that you create and use a RAM user to invoke API operations or perform routine O&M. The RAM user must have permissions to manage Simple Log Service resources and Operation logs. For more information, see Create a RAM user and grant permissions to the RAM user.
-
The name, region, and Logstore name of the project to which the logs you want to query belong are identified. For more information about how to query the information, see Manage a project and Manage a Logstore.
-
Simple Log Service has limits on log queries. Design appropriate query and analytic statements and configure appropriate query time ranges. For more information, see Limits on log queries and Limits on log analysis.
-
Indexes are configured before you query logs. For more information, see Create indexes.
-
When the number of logs involved in a query changes significantly, the Simple Log Service API cannot predict how many times this operation must be invoked to obtain the complete results. Therefore, you must check the x-log-progress status value in the response of each request to determine whether you need to repeatedly invoke this operation to obtain the final complete results. Each repeated invocation of this operation consumes the same number of query CUs.
-
After logs are written to a Logstore, the latency for the Simple Log Service query operations (GetHistograms and GetLogs) to retrieve the logs varies based on the log type. Simple Log Service classifies logs into the following two types based on the log UNIX timestamp:
Real-time data: The time point in the log is within the range of (current server time - 180 seconds, current server time + 900 seconds]. For example, if the log time is UTC 2014-09-25 12:03:00 and the server receives the log at UTC 2014-09-25 12:05:00, the log is processed as real-time data. This usually occurs in normal scenarios.
Historical data: The time point in the log is within the range of [current server time - 7 × 86400 seconds, current server time - 180 seconds). For example, if the log time is UTC 2014-09-25 12:00:00 and the server receives the log at UTC 2014-09-25 12:05:00, the log is processed as historical data. This usually occurs in data backfill scenarios. The latency from when real-time data is written to when it can be queried is about 3 seconds.
Simple Log Service calculates the difference between the log time (field name: time) and the server receipt time (field name: tag:receive_time). If the difference is within the range of (-180 seconds, 900 seconds], the data is real-time data. If the difference is within the range of [-7 × 86400 seconds, -180 seconds), the data is historical data.
Simple Log Service provides GetLogs query examples for Java and Python SDKs. For more information, see Java GetLogs example and Python GetLogs example.
Authentication information
The following table lists the authorization information corresponding to this API operation. You can add this information to the Action element of a RAM access policy statement to grant RAM users or RAM roles the permissions to invoke this API operation.
| Action | Resource in authorization policy |
log:GetLogStoreLogs | acs:log:{#regionId}:{#accountId}:project/{#ProjectName}/logstore/{#LogstoreName} |
Try it now
Test
RAM authorization
Request syntax
POST /logstores/{logstore}/logs HTTP/1.1
Path Parameters
|
Parameter |
Type |
Required |
Description |
Example |
| logstore |
string |
Yes |
The name of the Logstore. |
example-logstore |
Request parameters
|
Parameter |
Type |
Required |
Description |
Example |
| project |
string |
Yes |
The name of the project. |
ali-test-project |
| Accept-Encoding |
string |
No |
The compression method. |
lz4 |
| body |
object |
No |
The request structure. |
|
| from |
integer |
Yes |
The start time of the query. This time refers to the log time specified when the log data is written. The time range defined by the from and to request parameters follows the left-closed and right-open principle, which means the time range includes the start time but excludes the end time. If the values of from and to are the same, the time range is invalid, and the function directly returns an error. The time is a UNIX timestamp, which represents the number of seconds that have elapsed since 00:00:00 UTC on January 1, 1970. |
1627268185 |
| to |
integer |
Yes |
The end time of the query. This time refers to the log time specified when the log data is written. The time range defined by the from and to request parameters follows the left-closed and right-open principle, which means the time range includes the start time but excludes the end time. If the values of from and to are the same, the time range is invalid, and the function directly returns an error. The time is a UNIX timestamp, which represents the number of seconds that have elapsed since 00:00:00 UTC on January 1, 1970. |
1627268185 |
| line |
integer |
No |
The maximum number of logs to return. This parameter is valid only when the query parameter is a query statement. Minimum value: 0. Maximum value: 100. Default value: 100. |
100 |
| offset |
integer |
No |
The starting line of the query. This parameter is valid only when the query parameter is a query statement. Default value: 0. |
0 |
| reverse |
boolean |
No |
Specifies whether to return logs in descending order of log UNIX timestamps, accurate to the minute. Valid values:
Note When the query parameter is a query statement, the reverse parameter is valid and specifies the sorting of the returned logs. When the query parameter is a query and analytic statement, the reverse parameter is invalid. The sorting is specified by the ORDER BY syntax in the SQL analytic statement. If ORDER BY is ASC (default), the sorting is ascending. If ORDER BY is DESC, the sorting is descending. |
false |
| powerSql |
boolean |
No |
Specifies whether to enable Dedicated SQL. Default value: false. |
false |
| session |
string |
No |
The query parameters. |
mode=scan |
| topic |
string |
No |
The log topic. |
topic |
| query |
string |
No |
The query statement or analytic statement. For more information, see Query overview and Analysis overview. To use Dedicated SQL, add Note: When the query parameter contains an analytic statement (SQL statement), the line and offset parameters of this operation are invalid. We recommend setting them to 0 and using the LIMIT syntax in the SQL statement for pagination. For more information, see Paginate query and analysis results. |
status: 401 | SELECT remote_addr,COUNT(*) as pv GROUP by remote_addr ORDER by pv desc limit 5 |
| forward |
boolean |
No |
Specifies whether to page forward or backward in a scan or phrase query. |
false |
| highlight |
boolean |
No |
Specifies whether to enable highlighting. |
false |
| isAccurate |
boolean |
No |
Specifies whether to enable nanosecond-level ordering. |
true |
Response elements
|
Element |
Type |
Description |
Example |
|
object |
The log array. Each element in the array is a log. |
||
| meta |
object |
The metadata. |
|
| progress |
string |
Indicates whether the query results are complete. |
Complete |
| aggQuery |
string |
The SQL part after the vertical bar (|) in the query statement. |
select * |
| whereQuery |
string |
The part before the vertical bar (|) in the query statement. |
status: 200 and request_method: GET |
| hasSQL |
boolean |
Indicates whether the query is an SQL query. |
false |
| processedRows |
integer |
The number of rows processed in this query. |
10000 |
| elapsedMillisecond |
integer |
The time consumed by this query, in milliseconds. |
5 |
| cpuSec |
number |
The core-hours consumed by Dedicated SQL. |
0.002 |
| cpuCores |
integer |
The number of CPU cores used. |
3 |
| keys |
array |
The list of result column names. |
|
|
string |
The list of result column names. |
key |
|
| terms |
array<object> |
The types and aggregation information of the columns. |
|
|
object |
The types and aggregation information of the columns. |
{"term":"*","key":""} |
|
| limited |
integer |
The limit on the number of entries. This is returned if the SQL statement does not contain a LIMIT clause. |
100 |
| mode |
integer |
The query mode. Valid values:
|
0 |
| phraseQueryInfo |
object |
The phrase query information. |
|
| scanAll |
boolean |
Indicates whether all logs have been scanned. |
true |
| beginOffset |
integer |
The starting offset after index filtering for the current scan results. |
0 |
| endOffset |
integer |
The ending offset after index filtering for the current scan results. |
0 |
| endTime |
integer |
The end time after index filtering for the current scan results. |
1760530000000 |
| scanBytes |
integer |
The amount of scanned data returned during a scan, in bytes. |
1024 |
| highlights |
array<object> |
The highlighted content. |
[{"remote_addr":"198.51.XXX.XXX","request_method":"GET","status":"500"}] |
|
object |
The highlighted content. |
{"remote_addr":"198.51.XXX.XXX","request_method":"GET","status":"500"} |
|
| count |
integer |
The number of log rows returned by this query request. |
6 |
| processedBytes |
integer |
The volume of logs processed in the query. |
10000 |
| isAccurate |
boolean |
Specifies whether to enable nanosecond-level ordering. |
true |
| columnTypes |
array |
The |
|
|
string |
The data type. |
long |
|
| telementryType |
string |
The observable data type. |
None |
| data |
array<object> |
The returned data. |
[{ "remote_addr": "198.51.XXX.XXX", "status": "500", "request_method": "GET", "request_uri": "/api/v1/users", "__source__": "192.168.1.1", "__time__": "1649902984", "__tag__:__hostname__": "web-server-01" }] |
|
object |
The returned data. |
{ "remote_addr": "198.51.XXX.XXX", "status": "500", "request_method": "GET", "request_uri": "/api/v1/users", "__source__": "192.168.1.1", "__time__": "1649902984", "__tag__:__hostname__": "web-server-01" } |
|
|
string |
The returned data. |
198.51.XXX.XXX |
Examples
Success response
JSON format
{
"meta": {
"progress": "Complete",
"aggQuery": "select *",
"whereQuery": "*",
"hasSQL": false,
"processedRows": 10000,
"elapsedMillisecond": 5,
"cpuSec": 0.002,
"cpuCores": 3,
"keys": [
"key"
],
"terms": [
{
"test": "test",
"test2": 1
}
],
"limited": 100,
"mode": 0,
"phraseQueryInfo": {
"scanAll": true,
"beginOffset": 0,
"endOffset": 0,
"endTime": 1760530000000
},
"scanBytes": 1024,
"highlights": [
{
"remote_addr": "198.51.XXX.XXX",
"request_method": "GET",
"status": "500"
}
],
"count": 6,
"processedBytes": 10000,
"isAccurate": true,
"columnTypes": [
"long"
],
"telementryType": "None"
},
"data": [
{
"key": "[]"
}
]
}
Error codes
See Error Codes for a complete list.
Release notes
See Release Notes for a complete list.