Writes logs to a Logstore.
Usage notes
An AccessKey pair is created and obtained. For more information, see AccessKey pair.
The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations in Log Service is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. Make sure that the RAM user has the management permissions on Log Service resources. For more information, see Create a RAM user and authorize the RAM user to access Log Service.
The information that is required to query logs is obtained. The information includes the name of the project to which the logs belong, the region of the project, and the name of the Logstore to which the logs belong. For more information, see Manage a project and Manage a Logstore.
When you call the PostLogStoreLogs operation to write logs to Log Service, Log Service checks the format of the logs. If a log does not meet the format requirements, the request fails, and no logs are written to Log Service.
You can write logs only in the Protocol Buffers (Protobuf) format by using log groups. For more information, see Data encoding.
You can write logs in one of the following modes:
LoadBalance: In this mode, logs are randomly written to a shard that is available in the specified Logstore. This mode delivers high availability for write operations and is suitable for data consumption scenarios in which you do not need to preserve the order of logs.
KeyHash: In this mode, a hash key is added to the request parameters. The shard to which logs are written is determined based on the hash key. The hash key is optional. If you do not configure the hash key, logs are written to shards in LoadBalance mode. For example, Log Service can write data from a producer such as an instance to a shard based on the hash value of the instance name. This ensures that the data that is written to the shard is ordered and the data in the shard is consumed based on the order. This way, when a shard is split or when shards are merged, the data that contains the same hash key is included only in one shard at a time. For more information, see Shard.
The maximum size of raw logs that can be written to Log Service each time the PostLogStoreLogs operation is called is 10 MB. We recommend that you write a log whose values do not exceed 1 MB in size when log groups are used. Historical versions of SDKs may have different limits. We recommend that you upgrade your SDK to the latest version.
You cannot call the PostLogStoreLogs operation in OpenAPI Explorer.
Debugging
Request headers
This operation uses only common request headers. For more information, see Common request headers.
Request syntax
POST /logstores/{logstore}/shards/lb HTTP/1.1
Request parameters
Parameter | Type | Position | Required | Example | Description |
project | String | Host | Yes | ali-test-project | The name of the project. |
logstore | String | Path | Yes | ali-test-logstore | The name of the Logstore. |
String | Body | No | Compressed data in the Protobuf format | The data to write. For more information about the compressed data in the Protobuf format, see Data model and Data encoding. |
Response parameters
Parameter | Type | Example | Description |
Server | String | nginx | The name of the server. |
Content-Type | String | application/json | The content type of the response body. |
Content-Length | String | 0 | The content length of the response body. |
Connection | String | close | Indicates whether the connection is persistent. Valid values:
|
Date | String | Sun, 27 May 2018 08:25:04 GMT | The time when the response was returned. |
x-log-requestid | String | 5B0A6B60BB6EE39764D458B5 | The request ID. |
Examples
Sample requests
POST /logstores/ali-test-logstore/shards/lb HTTP/1.1
Host:ali-test-project.cn-hangzhou.log.aliyuncs.com
Content-Type:application/json
"Compressed data in the Protobuf format"
Sample success responses
JSON
format
HTTP/1.1 200 OK
Error codes
For a list of error codes, see Service error codes.
HTTP status code | Error code | Error message | Description |
400 | PostBodyInvalid | Fail to parse protobuf. | The logs in the Protobuf format are invalid and cannot be parsed. |
400 | PostBodyInvalid | Loggroup contains zero logs. | No logs exist in the log group. |
400 | PostBodyUncompressError | Post body uncompressed fail. | A log fails to be decompressed. |
404 | ProjectNotExist | Project does not exist. | The specified project does not exist. |
404 | LogStoreNotExist | Logstore does not exist. | The specified Logstore does not exist. |
413 | PostBodyTooLarge | Body size {bodySize} must little than 10485760. | The request body before compression exceeds 10 MB in size. |
500 | InternalServerError | Specified Server Error Message. | An internal server error has occurred. |
For more information, see Common error codes.