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
1POST /v1/logstore/{logStoreName}/logrecord?project={project} HTTP/1.1
2Host: <Endpoint>
3Authorization: <Authorization String>
4Content-Type: application/json; charset=utf-8
5
6{
7 "logStreamName": <logStreamName>,
8 "type": <type>,
9 "logRecords": [
10 {
11 "message": <message>,
12 "timestamp": <timestamp>
13 }
14 ],
15 "tags": [
16 {
17 "k": "<tagKey>",
18 "v": "<tagValue>"
19 }
20 ]
21}
- 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
Text1POST /v1/logstore/demo/logrecord?project=default HTTP/1.1 2Host: bls-log.bj.baidubce.com 3Authorization: bce-auth-v1/18717522d39411e9b721df098b0b908c/2019-09-10T07:00:20Z/1800/content-type;host;x-bce-date;x-bce-request-id/6a7cb6c9ac7ec156c805e55e7d0bcfc443b47feee97cf099c1c0d93a0b4c8304 4Content-Type: application/json; charset=utf-8 5{ 6 "logStreamName": "my-stream", 7 "type": "TEXT", 8 "logRecords": [ 9 { 10 "message": "this is a log record", 11 "timestamp": 1453209131020 12 } 13 ] 14}- TEXT log, including the tag
Text1POST /v1/logstore/demo/logrecord?project=default HTTP/1.1 2Host: bls-log.bj.baidubce.com 3Authorization: bce-auth-v1/18717522d39411e9b721df098b0b908c/2019-09-10T07:00:20Z/1800/content-type;host;x-bce-date;x-bce-request-id/6a7cb6c9ac7ec156c805e55e7d0bcfc443b47feee97cf099c1c0d93a0b4c8304 4Content-Type: application/json; charset=utf-8 5{ 6 "logStreamName": "my-stream", 7 "type": "TEXT", 8 "logRecords": [ 9 { 10 "message": "this is a log record", 11 "timestamp": 1453209131020 12 } 13 ], 14 "tags": [ 15 { 16 "k": "hostname", 17 "v": "localhost" 18 } 19 ] 20}- JSON log
Text1POST /v1/logstore/demo/logrecord?project=default HTTP/1.1 2Host: bls-log.bj.baidubce.com 3Authorization: bce-auth-v1/18717522d39411e9b721df098b0b908c/2019-09-10T07:00:20Z/1800/content-type;host;x-bce-date;x-bce-request-id/6a7cb6c9ac7ec156c805e55e7d0bcfc443b47feee97cf099c1c0d93a0b4c8304 4Content-Type: application/json; charset=utf-8 5{ 6 "logStreamName": "my-stream", 7 "type": "JSON", 8 "logRecords": [ 9 { 10 "message": "{\"level\":\"info\", \"status\": 200, \"cost\": 304.87}", 11 "timestamp": 1453209131020 12 } 13 ] 14}- JSON log, including the raw text (@raw)
Text1POST /v1/logstore/demo/logrecord?project=default HTTP/1.1 2Host: bls-log.bj.baidubce.com 3Authorization: bce-auth-v1/18717522d39411e9b721df098b0b908c/2019-09-10T07:00:20Z/1800/content-type;host;x-bce-date;x-bce-request-id/6a7cb6c9ac7ec156c805e55e7d0bcfc443b47feee97cf099c1c0d93a0b4c8304 4Content-Type: application/json; charset=utf-8 5{ 6 "logStreamName": "my-stream", 7 "type": "JSON", 8 "logRecords": [ 9 { 10 "message": "{\"@raw\":\"info 200 304.87ms this is a log record.\", \"level\":\"info\", \"status\": 200, \"cost\": 304.87}", 11 "timestamp": 1453209131020 12 } 13 ] 14} - Response example
1HTTP/1.1 200
2Content-Type: application/json; charset=utf-8
3X-Bce-Request-Id: 2eeba101-4cc7-4cfe-b5ac-a3be8d060e33
4Date: Fri, 10 Apr 2020 04:42:37 GMT
