百度智能云

All Product Document

          Log Service

          Push log PushLogRecord

          Description

          Support bulk pushing of log records to the BLS platform. The log record format can be either TEXT or JSON. For TEXT log records, logs remain unprocessed; for JSON log records, JSON fields are automatically identified (only first-level fields are currently supported, nested fields are not yet supported).

          To upload both processed specific fields and raw log text, use the JSON format with the raw log text included in JSON (@raw as the key and raw log text as the value). When processing @raw, BLS will treat its content as the raw log text.

          Request

          • Request syntax
          POST /v1/logstore/{logStoreName}/logrecord?project={project} HTTP/1.1
          Host: <Endpoint>
          Authorization: <Authorization String>
          Content-Type: application/json; charset=utf-8
          
          {
            "logStreamName": <logStreamName>,
            "type": <type>,
            "logRecords": [
              {
                "message": <message>,
                "timestamp": <timestamp>
              }
            ],
            "tags": [
              {
                "k": "<tagKey>",
                "v": "<tagValue>"
              }
            ]
          }
          • Request headers

          No additional headers are required beyond the standard request headers.

          • Request parameters
          Parameter name Types Required or not Parameter location Description
          project String No Query Project name, default
          logStoreName String Yes Path Logstore name
          logStreamName String No RequestBody Logstream name, composed of at most 192 characters which are only limited to: a-z, A-Z, 0-9, “_”, “-”, “.” , “/”
          type String No RequestBody Data type, JSON/TEXT; default: TEXT
          logRecords List<LogRecord> Yes RequestBody Logrecord
          tags List<Tag> No RequestBody Log tag

          Therein, the element structure of each logrecord in logrecords array is as follows:

          Field name Types Description
          message String The content of logrecord
          timestamp Int Logrecord timestamp, accurate to millisecond

          The element structure of each tag in tags array is as follows:

          Field name Types Description
          k String Log tag key
          v String Log tag value

          Response

          • Response headers

          No additional headers are required beyond the standard response headers.

          • Response parameters

          None

          Error code

          Apart from standard error codes, the following codes may be returned:

          Error code Error message Description HTTP status code
          InvalidParameter Request param invalid: [param] param invalid 400
          InvalidLogRecord The logRecord is not well-formed: [msg] msg indicates the specific error content 400
          LogStoreStopped LogStore stopped LogStore write operations blocked due to debt 403
          LogStoreNotFound LogStore not found LogStore not found 404
          LogStoreNotReady LogStore not ready LogStore in initialization 409
          RequestLimited Request frequency is too high, please slow down Request frequency is too high 429

          Example

          • Request example

            • TEXT log
            POST /v1/logstore/demo/logrecord?project=default HTTP/1.1
            Host: bls-log.bj.baidubce.com
            Authorization: bce-auth-v1/18717522d39411e9b721df098b0b908c/2019-09-10T07:00:20Z/1800/content-type;host;x-bce-date;x-bce-request-id/6a7cb6c9ac7ec156c805e55e7d0bcfc443b47feee97cf099c1c0d93a0b4c8304
            Content-Type: application/json; charset=utf-8
            {
              "logStreamName": "my-stream",
              "type": "TEXT",
              "logRecords": [
                {
                  "message": "this is a log record",
                  "timestamp": 1453209131020
                }
              ]
            }
            • TEXT log, including the tag
            POST /v1/logstore/demo/logrecord?project=default HTTP/1.1
            Host: bls-log.bj.baidubce.com
            Authorization: bce-auth-v1/18717522d39411e9b721df098b0b908c/2019-09-10T07:00:20Z/1800/content-type;host;x-bce-date;x-bce-request-id/6a7cb6c9ac7ec156c805e55e7d0bcfc443b47feee97cf099c1c0d93a0b4c8304
            Content-Type: application/json; charset=utf-8
            {
              "logStreamName": "my-stream",
              "type": "TEXT",
              "logRecords": [
                {
                  "message": "this is a log record",
                  "timestamp": 1453209131020
                }
              ],
              "tags": [
                {
                    "k": "hostname",
                    "v": "localhost"
                }
              ]
            }
            • JSON log
            POST /v1/logstore/demo/logrecord?project=default HTTP/1.1
            Host: bls-log.bj.baidubce.com
            Authorization: bce-auth-v1/18717522d39411e9b721df098b0b908c/2019-09-10T07:00:20Z/1800/content-type;host;x-bce-date;x-bce-request-id/6a7cb6c9ac7ec156c805e55e7d0bcfc443b47feee97cf099c1c0d93a0b4c8304
            Content-Type: application/json; charset=utf-8
            {
              "logStreamName": "my-stream",
              "type": "JSON",
              "logRecords": [
                {
                  "message": "{\"level\":\"info\", \"status\": 200, \"cost\": 304.87}",
                  "timestamp": 1453209131020
                }
              ]
            }
            • JSON log, including the raw text (@raw)
            POST /v1/logstore/demo/logrecord?project=default HTTP/1.1
            Host: bls-log.bj.baidubce.com
            Authorization: bce-auth-v1/18717522d39411e9b721df098b0b908c/2019-09-10T07:00:20Z/1800/content-type;host;x-bce-date;x-bce-request-id/6a7cb6c9ac7ec156c805e55e7d0bcfc443b47feee97cf099c1c0d93a0b4c8304
            Content-Type: application/json; charset=utf-8
            {
              "logStreamName": "my-stream",
              "type": "JSON",
              "logRecords": [
                {
                  "message": "{\"@raw\":\"info 200 304.87ms this is a log record.\", \"level\":\"info\", \"status\": 200, \"cost\": 304.87}",
                  "timestamp": 1453209131020
                }
              ]
            }
          • Response example
          HTTP/1.1 200
          Content-Type: application/json; charset=utf-8
          X-Bce-Request-Id: 2eeba101-4cc7-4cfe-b5ac-a3be8d060e33
          Date: Fri, 10 Apr 2020 04:42:37 GMT
          Previous
          LogStore Related APIs
          Next
          Obtain logrecord PullLogRecord