---
title: "Build from source"
description: "Build the Logbrook binary with Cargo and run it in the foreground."
---

> Documentation Index
> Fetch the complete documentation index at: https://sandrinodm.github.io/logbrook/llms.txt
> Use this file to discover all available pages before exploring further.

# Build from source

Most setups don't need this: every release publishes a container image, which the [quickstart](https://sandrinodm.github.io/logbrook/get-started/quickstart/) and [Docker Compose](https://sandrinodm.github.io/logbrook/get-started/docker-compose/) pages use. Build from source to run an unreleased commit, a platform without an image, or the binary without Docker.

Build the `logbrook` executable from a checkout, run it on `127.0.0.1:3100`, send an event, and search it. Run every command from the repository root.

## Prerequisites

- **Rust**, installed with [rustup](https://rustup.rs). The repository pins Rust 1.99.1 in `rust-toolchain.toml`, and rustup installs that version on your first `cargo` command.
- **A C++ compiler** for the bundled DuckDB build. On macOS, install the Xcode command-line tools with `xcode-select --install`.
- **`openssl` and `curl`** for the commands below.

If `cargo` is not found right after installing Rust, run `. "$HOME/.cargo/env"` or open a new shell.

## Build and run

1. **Clone and build**

   ```sh
   git clone https://github.com/sandrinodm/logbrook.git
   cd logbrook
   cargo build --package logbrook --locked --release
   ```

   The first build compiles DuckDB from source and takes several minutes.
2. **Start the server**

   Generate the two credentials, print them for the second terminal, validate the configuration, and start the server.

   ```sh
   export LOGBROOK_INGEST_TOKEN="$(openssl rand -hex 24)"
   export LOGBROOK_READ_TOKEN="$(openssl rand -hex 24)"
   echo "Ingest token: $LOGBROOK_INGEST_TOKEN"
   echo "Read token:   $LOGBROOK_READ_TOKEN"

   target/release/logbrook check-config
   target/release/logbrook serve
   ```

   `serve` stays in the foreground and writes JSON logs to stderr. Press Ctrl-C to stop it. Without a configuration file, Logbrook listens on `127.0.0.1:3100`, stores data in `./data`, and keeps events for seven days with no disk-size target.
3. **Send an event**

   In a second terminal in the repository root, set the ingestion token and send one event to an index named `payments`.

   ```sh
   export LOGBROOK_INGEST_TOKEN='<ingest token from the first terminal>'

   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\" }]"
   ```

   ```json
   { "accepted": 1 }
   ```

   The first authorized write to a new index creates it.
4. **Search**

   Set the read token, then query the index with the CLI:

   ```sh
   export LOGBROOK_READ_TOKEN='<read token from the first terminal>'
   target/release/logbrook query payments --since 1h
   ```

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

## Use a configuration file

Settings resolve in this order: built-in defaults, then an optional TOML file passed with `--config`, then supported `LOGBROOK_*` environment variables.

```sh
cp logbrook.example.toml logbrook.local.toml
# Edit logbrook.local.toml and replace every replace-with-... credential.
target/release/logbrook --config logbrook.local.toml check-config
target/release/logbrook --config logbrook.local.toml serve
```

Git ignores `*.local.toml` files. Environment variables override the file, so unset the token variables from the steps above to use the file's credentials. See [the configuration file](https://sandrinodm.github.io/logbrook/configure/configuration-file/).

## Next steps

- [Run with Docker Compose](https://sandrinodm.github.io/logbrook/get-started/docker-compose/) — A persistent deployment with a data volume.
- [Configuration file](https://sandrinodm.github.io/logbrook/configure/configuration-file/) — Every setting, with defaults.
- [CLI reference](https://sandrinodm.github.io/logbrook/reference/cli/) — query, count and index management.

Source: https://sandrinodm.github.io/logbrook/get-started/build-from-source/index.mdx
