Skip to content

Quickstart

Run Logbrook with Docker, send an event, and search it in five minutes.

Updated

Run the published container image, send one event, and search it. Nothing persists after you remove the container; for a setup that keeps its data, use Docker Compose.

Prerequisites

Docker, plus curl and openssl on the host.

Run it

  1. Generate credentials

    Logbrook needs a separate ingestion token and read token. Each must be 16 to 512 visible ASCII characters with no whitespace.

    export LOGBROOK_INGEST_TOKEN="$(openssl rand -hex 24)"
    export LOGBROOK_READ_TOKEN="$(openssl rand -hex 24)"
  2. Start the container

    The image sets LOGBROOK_BIND=0.0.0.0:3100 and stores data in /data. The 127.0.0.1: prefix publishes the port on the loopback interface only.

    docker run -d --name logbrook \
      -p 127.0.0.1:3100:3100 \
      -e LOGBROOK_INGEST_TOKEN \
      -e LOGBROOK_READ_TOKEN \
      ghcr.io/sandrinodm/logbrook:0.5.0

    Check that it is up:

    docker exec logbrook logbrook healthcheck

    If the check fails, run docker logs logbrook. The server writes JSON logs to stderr.

  3. Send an event

    This writes one event to an index named payments. The first authorized write to a new index creates it.

    curl --fail http://127.0.0.1:3100/indexes/payments/logs/ingest \
      -H "Authorization: Bearer $LOGBROOK_INGEST_TOKEN" \
      -H 'Content-Type: application/json' \
      --data "[{ \"time\": $(( $(date +%s) * 1000 )), \"level\": 30, \"service\": \"checkout\", \"msg\": \"Order accepted\", \"orderId\": \"demo-1\" }]"
    { "accepted": 1 }

    time is a Unix timestamp in milliseconds, level is a nonnegative integer (30 is Pino’s info), and msg is the message. Other fields, such as orderId, become attributes.

  4. Search with the CLI

    The container already has the read token in its environment, so run the CLI inside it:

    docker exec logbrook logbrook query payments --since 1h

    Add --json to see the complete record, including the orderId attribute.

  5. Search with curl

    Over HTTP, pass the read token and a time range: from (inclusive) and to (exclusive) in Unix milliseconds. This asks for the last hour:

    now=$(( $(date +%s) * 1000 ))
    curl --fail -H "Authorization: Bearer $LOGBROOK_READ_TOKEN" \
      "http://127.0.0.1:3100/indexes/payments/logs?from=$(( now - 3600000 ))&to=$(( now + 60000 ))&limit=10"
  6. Stop and clean up

    docker rm -f logbrook

    Without a volume, removing the container deletes the data.

Next steps

Type to search…

↑↓ navigate↵ selectEsc close