Queries logs in a Logstore of a specified project.
Description
- If the number of logs in a Logstore significantly changes, Log Service cannot predict the number of times you must call this API operation to obtain complete results. In this case, you must check the value of the x-log-progress parameter in the returned results of each request. You can also call this API operation again to obtain the complete results based on the value of this parameter. Each time you call this operation, the same number of charge units (CUs) are consumed.
- After a log is written to a Logstore, you can call the GetHistograms and GetLogs operations
to query the log. The latency of the query varies based on the type of the log. Log
Service classifies logs into the following two types based on the log timestamp:
- Real-time data: The difference between the time in a log of this type and the current time on the server is within the interval (-180 seconds, 900 seconds]. For example, if a log was generated at 12:03:00 UTC, September 25, 2014 and the server received the log at 12:05:00 UTC, September 25, 2014, the server processes the log as real-time data. Logs of this type are generated in standard query scenarios.
-
Historical data: The difference between the time in a log of this type and the current time on the server is within the interval [-604,800 seconds, -180 seconds). For example, if a log was generated at 12:00:00 UTC, September 25, 2014 and the server received the log at 12:05:00 UTC, September 25, 2014, the server processes the log as historical data. Logs of this type are generated in data supplement scenarios.
After real-time data is written to a Logstore, the data can be queried with a maximum latency of 3 seconds. The latency of 99.9% of queries is within 1 second.
Request headers
The GetLogs operation does not have operation-specific request headers and uses only common request headers. For more information, see Common request headers.
Request syntax
GET /logstores/{logstoreName}/index HTTP/1.1
Request parameters
Parameter | Type | Position | Required | Example | Description |
---|---|---|---|---|---|
logstorename | String | Path | Yes | nginx-demo |
The name of the Logstore. |
type | String | Query | Yes | log |
The type of the data in the Logstore. This parameter must be set to log in the GetLogs operation. |
from | Long | Query | Yes | 1627268185 |
The start time of the time range that is specified in the request. This parameter specifies the time when log data is written to a Logstore.
|
to | Long | Query | Yes | 1627269085 |
The end time of the time range that is specified in the request. This parameter specifies the time when log data is written to a Logstore.
|
topic | String | Query | No | topic |
The topic of the logs. The default value is double quotation marks (""). For more information, see Topic. |
query | String | Query | Yes | status: 401 | SELECT remote_addr,COUNT(*) as pv GROUP by remote_addr ORDER by pv desc limit 5 |
The search statement or analytic statement. For more information, see Log search overview and Log analysis overview. If you add Note If you specify an analytic statement in the query parameter, the line and offset parameters
are invalid for this operation. In this case, we recommend that you set the line and
offset parameters to 0 and use a LIMIT clause to limit the number of entries to return
on each page. For more information, see Paged query.
|
line | Long | Query | No | 100 |
The maximum number of logs to return for the request. This parameter is valid only when the query parameter is set to a search statement. Minimum value: 0. Maximum value: 100. Default value: 100. |
offset | Long | Query | No | 0 |
The line from which the query starts. This parameter is valid only when the query parameter is set to a search statement. Default value: 0. |
reverse | Boolean | Query | No | false |
Specifies whether to return logs in reverse order by log timestamp. The log timestamps are accurate to minutes.
Notice
|
powerSql | Boolean | Query | No | false |
Specifies whether to use the Dedicated SQL feature. For more information, see Enable Dedicated SQL.
You can use the powerSql or query parameter to configure Dedicated SQL. |
Response parameters
Parameter | Type | Example | Description |
---|---|---|---|
x-log-progress | String | Complete |
The status of the query results. Valid values:
|
x-log-count | Long | 10000 |
The total number of logs in the query results. |
logs | Object |
The returned logs. |
|
__time__ | Long | 1627268185 |
The timestamp of the log. The timestamp follows the UNIX time format. It is the number of seconds that have elapsed since 00:00:00 UTC, Thursday, January 1, 1970. |
__source__ | String | None |
The log source that is specified when logs are written. For example, the source can be the IP address of the host where the log is generated. |
Examples
Sample requests
GET /logstores/{logstoreName}/index?type=log&from=1627268185&to=1627269085&topic=topic&query=status: 401 | SELECT remote_addr,COUNT(*) as pv GROUP by remote_addr ORDER by pv desc limit 5&line=100&offset=0&reverse=false&powerSql=false HTTP/1.1
Host:ali-test-project.cn-hangzhou.log.aliyuncs.com
Content-Type:application/json
Sample success responses
JSON
format
HTTP/1.1 200 OK
Content-Type:application/json
{
"x-log-progress" : "Complete",
"x-log-count" : 10000,
"logs" : {
"__time__" : 1627268185,
"__source__" : "None"
}
}
Error codes
For a list of error codes, visit the API Error Center.