Queries log data from a Logstore in the specified project.
Operation description
Simple Log Service supports scheduled SQL jobs. For details, see Create a scheduled SQL job.
-
The Host in the request syntax consists of the project name and the Simple Log Service endpoint. Specify the project name in the Host.
-
Create and obtain an AccessKey pair. For details, see AccessKey pair.
Create and use a RAM user to make API calls or perform routine O&M. Using an Alibaba Cloud account AccessKey pair grants access to all APIs and poses a high security risk. Ensure the RAM user has the required permissions for Simple Log Service resources. For details, see Create and authorize a RAM user.
-
Obtain the project name, region, and Logstore name for the logs to query. See Manage a project and Manage a Logstore.
-
Simple Log Service imposes limits on log queries. Design appropriate query and analytic statements and set a reasonable time range. See Log query limits and Log analysis limits.
-
Configure indexes before querying logs. See Create indexes.
-
When the number of matching logs varies significantly, the API cannot predict how many calls are needed to retrieve the complete result. Check the
x-log-progressheader in each response to determine whether to repeat the call. Each repeated call consumes the same number of query capacity units (CUs). -
After a log is written to a Logstore, the latency before it becomes queryable through the GetHistograms and GetLogs operations depends on the log type. Simple Log Service classifies logs into two types based on their timestamps:
-
Real-time data: The log timestamp falls within (-180 seconds, 900 seconds] relative to the current server time. For example, if a log is generated at UTC 2014-09-25 12:03:00 and is received by the server at UTC 2014-09-25 12:05:00, the log is classified as real-time data. This is typical in normal scenarios. Real-time data becomes queryable in about 3 seconds.
-
Historical data: The log timestamp falls within [-7 x 86,400 seconds, -180 seconds) relative to the current server time. For example, if a log is generated at UTC 2014-09-25 12:00:00 and is received by the server at UTC 2014-09-25 12:05:00, the log is classified as historical data. This is typical in data backfill scenarios.
-
Simple Log Service calculates the difference between the log time (the __time__ field) and the server receipt time (the __tag__: receive_time field). If the difference falls within (-180 seconds, 900 seconds], the log is real-time data. If the difference falls within [-7 x 86,400 seconds, -180 seconds), the log is historical data.
-
Simple Log Service provides Java and Python SDK examples for the GetLogs operation. See GetLogs examples for Java and GetLogs examples for Python.
Authorization
The following table describes the authorization information required for this operation. Add this information to the Action element of a RAM access policy statement to grant RAM users or RAM roles the permission to call this operation.
| Action | Resource |
log:GetLogStoreLogs |
acs:log:{#regionId}:{#accountId}:project/{#ProjectName}/logstore/{#LogstoreName} |
Try it now
Test
RAM authorization
Request syntax
GET /logstores/{logstore}?type=log HTTP/1.1
Path Parameters
|
Parameter |
Type |
Required |
Description |
Example |
| logstore |
string |
Yes |
The Logstore to query. |
example-logstore |
Request parameters
|
Parameter |
Type |
Required |
Description |
Example |
| project |
string |
Yes |
The project name. |
ali-test-project |
| from |
integer |
Yes |
The start of the query time range, based on the log time specified when the log data was written.
Note
To avoid missing data, align the query time to the minute level. If a time range is specified in the analytic statement, that time range takes precedence. To specify a time in seconds within an analytic statement, use the from_unixtime function or the to_unixtime function to convert the time format. Examples:
|
1627268185 |
| to |
integer |
Yes |
The end of the query time range, based on the log time specified when the log data was written.
Note
To avoid missing data, align the query time to the minute level. If a time range is specified in the analytic statement, that time range takes precedence. To specify a time in seconds within an analytic statement, use the from_unixtime function or the to_unixtime function to convert the time format. Examples:
|
1627269085 |
| query |
string |
No |
The search statement or analytic statement. See Query overview and Analysis overview. To enable the Exclusive SQL feature, add Note
When the query parameter contains an analytic statement (SQL statement), the |
status: 401 | SELECT remote_addr,COUNT(*) as pv GROUP by remote_addr ORDER by pv desc limit 5 |
| topic |
string |
No |
The log topic. Default value: an empty string. See Topic. |
topic |
| line |
integer |
No |
Valid only when the query parameter is a search statement. Maximum number of logs to return. Valid values: 0 to 100. Default value: 100. See Page through query and analysis results. |
100 |
| offset |
integer |
No |
Valid only when the query parameter is a search statement. The starting row for the query. Default value: 0. See Page through query and analysis results. |
0 |
| reverse |
boolean |
No |
Whether to return logs in descending order of timestamp, with minute-level precision.
Important
|
false |
| powerSql |
boolean |
No |
Whether to enable the Exclusive SQL feature. See Enable the Exclusive SQL feature.
Alternatively, add |
false |
Response elements
|
Element |
Type |
Description |
Example |
|
array |
The log array. Each element is a log entry. |
||
|
object |
The log array. Each element is a log entry. |
[{'remote_addr': '198.51.XXX.XXX', 'pv': '1', '__source__': '', '__time__': '1649902984'}, {'remote_addr': '198.51.XXX.XXX', 'pv': '1', '__source__': '', '__time__': '1649902984'}, {'remote_addr': '198.51.XXX.XXX', 'pv': '1', '__source__': '', '__time__': '1649902984'}, {'remote_addr': '198.51.XXX.XXX', 'pv': '1', '__source__': '', '__time__': '1649902984'}, {'remote_addr': '198.51.100.XXX', 'pv': '1', '__source__': '', '__time__': '1649902984'}] |
Examples
Success response
JSON format
[
{
"test": "test",
"test2": 1
}
]
Error codes
See Error Codes for a complete list.
Release notes
See Release Notes for a complete list.