PutLogs

Updated at:

Writes log data to a specified Logstore.

Operation description

Note
  • The server checks the format of the log data written by each PutLogs request. If any log entry in the log data is not in compliance, the entire request fails and no log data is written.

  • Only log data in Protocol Buffers (PB) format is supported. The log data is presented in the form of a log group.

  • Two modes are available for writing log data:
    • Load balancing mode (LoadBalance): Automatically distributes the write load across all writable shards in the Logstore. This mode provides high write availability and is suitable for data consumption scenarios where strict ordering is not required. Request syntax:

      POST /logstores/logstoreName/shards/lb HTTP/1.1
      Authorization: LOG yourAccessKeyId:yourSignature
      Content-Type: application/x-protobuf
      Content-Length: Content Length
      Content-MD5: Content MD5
      Date: GMT Date
      Host: ProjectName.Endpoint
      x-log-apiversion: 0.6.0
      x-log-bodyrawsize: BodyRawSize
      x-log-compresstype: lz4
      x-log-signaturemethod: hmac-sha1
      <Compressed log data in PB format>
      

    • Key-based shard routing mode (KeyHash): Adds a key field to the URL parameters to determine which shard the data is written to. This parameter is optional. If no Settings are specified, the system automatically switches to the load balancing write mode. For example, you can hash the name of a producer (such as an instance) to a specific shard to ensure that the data written to and consumed from the shard is strictly ordered. During the shard merging and splitting process, a key is strictly guaranteed to exist in only one shard at any given time. Request syntax:

      POST /logstores/logstoreName/shards/route?key=14d2f850ad6ea48e46e4547edbbb27e0
      Authorization: LOG yourAccessKeyId:yourSignature
      Content-Type: application/x-protobuf
      Content-Length: Content Length
      Content-MD5: Content MD5
      Date: GMT Date
      Host: ProjectName.Endpoint
      x-log-apiversion: 0.6.0
      x-log-bodyrawsize: BodyRawSize
      x-log-compresstype: lz4
      x-log-signaturemethod: hmac-sha1
      <Compressed log data in PB format>
      

  • The maximum size of raw log data that can be written in a single PutLogs request is 10 MB. We recommend that the value part of each log entry in a log group does not exceed 1 MB. Earlier SDK versions may have different limits. Upgrade to the latest version to resolve such issues.

  • The SDK reference provides examples of using PutLogs with SDKs such as the Java and Python SDKs.

PB data

The data fields of compressed log data in PB format are described as follows. For details, see Data model and Data encoding methods.

  • Log.

ParameterTypeRequiredDescription
TimeIntegerYesThe log time. The value is a UNIX timestamp that represents the number of seconds that have elapsed since 00:00:00 UTC on January 1, 1970.
ContentsListYesThe list of log fields. The list must contain at least one element. For more information about the element type, see the Content table below.
  • Content.

ParameterTypeRequiredDescription
KeyStringYesThe custom key name.
ValueStringYesThe value corresponding to the custom key.
  • LogTag.

ParameterTypeRequiredDescription
KeyStringYesThe custom key name.
ValueStringYesThe value corresponding to the custom key.
  • LogGroup.

ParameterTypeRequiredDescription
LogsListYesThe list of logs. For more information about each element, see the Log table.
TopicStringNoThe log topic. This is a custom field used to distinguish log data with different characteristics.
SourceStringNoThe source of the log. For example, the IP address of the machine that generated the log.
LogTagsListYesThe list of log tags. For more information about each element, see LogTag.

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

No authorization for this operation. If you encounter issues with this operation, contact technical support.

Request syntax

POST /logstores/{logstore}/shards/lb HTTP/1.1

Path Parameters

Parameter

Type

Required

Description

Example

logstore

string

Yes

The name of the Logstore.

ali-test-logstore

Request parameters

Parameter

Type

Required

Description

Example

project

string

Yes

The name of the project.

ali-test-project

x-log-compresstype

string

Yes

The log compression type. Valid values: lz4 and gzip.

Valid values:

  • gzip :

    gzip mode.

  • lz4 :

    lz4 mode.

lz4

body LogGroup

No

The compressed log data in PB format.

Request headers

For more information about the common request headers of the Simple Log Service API, see Common request headers.

Sample requests:

POST /logstores/sls-test-logstore/shards/lb
{
    "Content-Length": 118,
    "Content-Type":"application/x-protobuf",
    "x-log-bodyrawsize":1356,
    "Host": "ali-test-project.cn-hangzhou-devcommon-intranet.sls.aliyuncs.com",
    "Content-MD5":"6554BD042149C844761C2C094A8FECCE",
    "Date":"Thu, 12 Nov 2015 06:54:26 GMT",
    "x-log-apiversion": "0.6.0",
    "x-log-compresstype":"lz4"
    "x-log-signaturemethod": "hmac-sha1",
    "Authorization":"LOG yourAccessKeyId:yourSignature"
}
<Binary data of logs in PB format compressed by using LZ4>

Response elements

Element

Type

Description

Example

None defined.

Response headers

The PutLogs operation does not have specific response headers. For more information about the common response headers of the Simple Log Service API, see Common response headers.

Response elements

If the HTTP status code 200 is returned, the request is successful. This operation does not return any response elements upon success.

Examples

Success response

JSON format

{}

Error codes

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.