You send events to Logbrook with one POST request per batch. The examples assume a running server and an ingestion token:
export LOGBROOK_URL=http://127.0.0.1:3100
export LOGBROOK_INGEST_TOKEN='<your ingestion token>'Endpoint and authentication
POST /indexes/{index}/logs/ingest
Authorization: Bearer <ingestion token>
Content-Type: application/json| Part | Detail |
|---|---|
| Path | /indexes/{index}/logs/ingest. The index name has 1 to 63 lowercase letters, digits, - or _, and starts with a letter or digit. |
| Default index | /logs/ingest writes to the default index. Use the named route in new clients. |
| Credential | An ingestion token in Authorization: Bearer. Read and admin tokens get 401. |
| Source | Set by the ingestion token. A payload field can’t override it. |
If the index doesn’t exist yet, the first authorized write creates it, as long as the server has a free index slot (four by default, including default). Creation happens before the body is validated, so a rejected batch can leave an empty index behind. See credentials and roles for tokens and index scopes.
Send a batch
A request body is either a JSON array or NDJSON.
now=$(jq -nr 'now * 1000 | floor')
jq -n --argjson now "$now" '
[
{time: ($now - 2000), level: 30, service: "checkout", name: "http",
hostname: "api-1", msg: "order accepted", requestId: "demo-001"},
{time: ($now - 1000), level: 50, service: "checkout", name: "http",
hostname: "api-1", msg: "payment timeout", requestId: "demo-002",
durationMs: 1200}
]
' |
curl --fail-with-body --silent --show-error \
"${LOGBROOK_URL%/}/indexes/apps/logs/ingest" \
-H "Authorization: Bearer $LOGBROOK_INGEST_TOKEN" \
-H 'Content-Type: application/json' --data-binary @-now=$(jq -nr 'now * 1000 | floor')
{
jq -nc --argjson now "$now" '{time: ($now - 2000), level: 30, service: "checkout", name: "http", hostname: "api-1", msg: "order accepted", requestId: "demo-001"}'
jq -nc --argjson now "$now" '{time: ($now - 1000), level: 50, service: "checkout", name: "http", hostname: "api-1", msg: "payment timeout", requestId: "demo-002", durationMs: 1200}'
} |
curl --fail-with-body --silent --show-error \
"${LOGBROOK_URL%/}/indexes/apps/logs/ingest" \
-H "Authorization: Bearer $LOGBROOK_INGEST_TOKEN" \
-H 'Content-Type: application/x-ndjson' --data-binary @-Both requests return:
{ "accepted": 2 }accepted is the number of events committed. A 200 means the whole batch is stored.
Body formats
| Format | Content-Type |
Body |
|---|---|---|
| JSON | application/json |
A nonempty array of objects, even for one event |
| NDJSON | application/x-ndjson or application/ndjson |
One object per line, no enclosing array. Blank lines are ignored. |
A request without a Content-Type is read as JSON. Parameters such as ; charset=utf-8 are accepted. Any other media type returns 400.
Event fields
| Input field | Requirement | Stored as |
|---|---|---|
time |
Required integer, Unix milliseconds, 0 to 253402300799999 |
event_time |
level |
Required integer, 0 to 2147483647 |
level |
msg |
Required string, an empty string is allowed | message |
service |
Optional string or null | service |
name |
Optional string or null | logger |
hostname |
Optional string or null | host |
pid |
Optional nonnegative 64-bit integer or null | pid |
| Any other key | Any JSON value within the limits | Nested under attributes |
These are Pino’s default field names and formats, so Pino output works without conversion. Logbrook doesn’t translate other formats. Pino’s numeric levels are 10 (trace), 20 (debug), 30 (info), 40 (warn), 50 (error) and 60 (fatal).
Missing optional fields come back as null. Other keys are kept as sent, including nested objects and arrays:
- A key named
id,source,event_time,received_at,message,hostorloggerbecomes an attribute. It never overrides the stored field. - An input
attributesobject stays nested, asattributes.attributes. Send custom fields at the top level so you can filter on them with attribute filters. - The server sets
id,received_atandsource.
Time window
Event times must fall between now - retention and now + max_future_skew_ms. Retention is seven days and future skew is five minutes by default. A batch with a time outside that window is rejected whole. To load older history, use the offline import.
Limits
A batch is accepted or rejected as a whole. One invalid, oversized or expired event rejects all of it. Defaults:
| Limit | Default |
|---|---|
| Request body | 1 MiB |
| One event on the wire | 64 KiB |
| Events per batch | 1,000 |
| String field or metadata key | 4 KiB (UTF-8 bytes) |
| JSON nesting depth | 16 |
| Body idle / total receive time | 5 / 30 seconds |
Limit batches by serialized bytes as well as event count. Operators can change these limits; see limits and errors.
Responses and errors
Errors are JSON objects like { "error": "explanation" }. The text is for people, so don’t parse it.
| Status | Meaning | What to do |
|---|---|---|
200 |
Batch committed | Nothing |
400 |
Invalid payload, missing msg, level or time, time outside the window, or unsupported Content-Type |
Fix the request. Retrying won’t help. |
401 |
Missing, unknown or wrong-role token | Use the ingestion token |
403 |
The token’s index scope excludes this index | Use an allowed index |
413 |
Body, event, field or batch size over a limit | Send smaller batches |
429 |
Server at capacity, or no free index slot. Includes Retry-After: 1. |
Retry with backoff, or reduce the rate |
503 |
Storage unavailable or server shutting down | Retry later |
504 |
Body receive deadline exceeded. The outcome may be uncertain. | Retry with the duplicate caveat below |
507 |
The index reached its size target | Review the index’s retention and size settings |
Retries and duplicates
Retry 429, 503 and network errors with bounded exponential backoff. Don’t retry 400, 401, 403 or 413 unchanged. When duplicates matter, add an attribute such as a batch or run ID so you can find and remove them from a query result. Logbrook has no API to delete individual events.
Verify the batch
Query with a read token:
export LOGBROOK_READ_TOKEN='<your read token>'
logbrook query apps --since 15m --service checkout --jsonThe CLI reads LOGBROOK_URL and LOGBROOK_READ_TOKEN. The read token must allow the ingestion token’s source. See search and filter.