GetLogsV2
Queries the raw log data in a specified Logstore of a project and returns the raw logs within a specified time range. The response is compressed during transmission.
Operation description
-
During the procedure, specify the compression method. Compression algorithms vary across different programming languages. For details, see the Accept-Encoding request parameter.
-
For more information, see GetLogs.
Authentication resources
The following table describes the authorization information for this API operation. You can add this information to the Action element of a RAM access policy statement to grant Resource Access Management (RAM) users or RAM roles the permissions to invoke this API operation.
| Action | Resource |
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. |
test-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 for the response content. SDK users do not need to specify this parameter because the SDK automatically handles compression and decompression.
Valid values:
|
lz4 |
| body |
object |
No |
The request struct. |
|
| from |
integer |
Yes |
The start time of the query. This time refers to the log time specified when log data is written. The time range specified by the from and to request parameters follows the left-closed and right-open principle. This 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 representing 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 log data is written. The time range specified by the from and to request parameters follows the left-closed and right-open principle. This 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 representing 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 set to a query statement rather than an analytic statement. Valid values: 0 to 100. Default value: 100. |
100 |
| offset |
integer |
No |
The start line of the query. This parameter is valid only when the query parameter is set to a query statement rather than an analytic statement. The value starts from 0. Default value: 0. |
0 |
| reverse |
boolean |
No |
Specifies whether to return logs in descending order of log timestamps, accurate to the minute. This parameter is valid only when the query parameter is set to a query statement rather than an analytic statement.
To sort logs in an analytic statement, use the ORDER BY syntax. If ORDER BY is set to ASC, logs are sorted in ascending order. This is the default value. If ORDER BY is set to DESC, logs are sorted in descending order. |
false |
| powerSql |
boolean |
No |
Specifies whether to enable Dedicated SQL. By default, Dedicated SQL is disabled. |
false |
| session |
string |
No |
The query parameters. |
mode=scan |
| topic |
string |
No |
The log topic. Default value: empty. |
"" |
| query |
string |
No |
The query statement or analytic statement. For more information, see Query overview and Analysis overview. To use Dedicated SQL, add set session parallel_sql=true; to the analytic statement in the query parameter. Example: * | set session parallel_sql=true; select count(*) as pv. Note: If the query parameter contains an analytic statement (SQL statement), the line and offset parameters of this API operation are invalid. We recommend that you set them to 0 and use the LIMIT syntax in the SQL statement to paginate results. 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 response data. |
||
| meta |
object |
The metadata of the response data. |
|
| progress |
string |
Indicates whether the query result is complete. Valid values:
|
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 |
All keys in the query result. |
|
|
string |
key |
key |
|
| terms |
array<object> |
All terms in the query statement. |
|
|
object |
The term. |
{"term":"*","key":""} |
|
| limited |
integer |
The limit on the number of entries. This parameter 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 start offset after index filtering for the current scan result. |
0 |
| endOffset |
integer |
The end offset after index filtering for the current scan result. |
0 |
| endTime |
integer |
The end time after index filtering for the current scan result. The time is a UNIX timestamp in milliseconds representing the number of milliseconds that have elapsed since 00:00:00 UTC on January 1, 1970. |
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 lines returned by this query request. |
1 |
| processedBytes |
integer |
The volume of logs processed by the query. |
10000 |
| isAccurate |
boolean |
Specifies whether to enable nanosecond-level ordering. |
true |
| columnTypes |
array |
The column types. |
|
|
string |
The column type. |
long |
|
| telementryType |
string |
The observable data type. |
None |
| data |
array<object> |
The returned result. |
[{ "remote_addr": "198.51.XXX.XXX", "pv": "1", "__source__": "", "__time__": "1649902984" }] |
|
object |
The returned data. |
{ "remote_addr": "198.51.XXX.XXX", "pv": "1", "__source__": "", "__time__": "1649902984" } |
|
|
string |
The returned data. |
198.51.XXX.XXX" |
Examples
Success response
JSON format
{
"meta": {
"progress": "Complete",
"aggQuery": "select *",
"whereQuery": "status: 200 and request_method: GET",
"hasSQL": false,
"processedRows": 10000,
"elapsedMillisecond": 5,
"cpuSec": 0.002,
"cpuCores": 3,
"keys": [
"key"
],
"terms": [
{
"term": "*",
"key": ""
}
],
"limited": 100,
"mode": 0,
"phraseQueryInfo": {
"scanAll": true,
"beginOffset": 0,
"endOffset": 0,
"endTime": 1
},
"scanBytes": 1024,
"highlights": [
{
"remote_addr": "198.51.XXX.XXX",
"request_method": "GET",
"status": "500"
}
],
"count": 1,
"processedBytes": 10000,
"isAccurate": true,
"columnTypes": [
"long"
],
"telementryType": "None"
},
"data": [
{
"key": "198.51.XXX.XXX\""
}
]
}
Error codes
See Error Codes for a complete list.
Release notes
See Release Notes for a complete list.