---
title: "Get started"
description: "Install Logbun, emit one audit event, flush it, and shut the logger down."
---

> Documentation Index
> Fetch the complete documentation index at: https://logbun-docs.abshahin.workers.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Get started

The shortest path from an empty project to one stored audit record. This walkthrough uses Bun and the built-in SQLite destination. For Node, Deno, or Workers, see [Installation](/installation) and the [runtime guides](/guides).

1. **Install**

```sh
   npm install logbun
   pnpm add logbun
   yarn add logbun
   bun add logbun
```

2. **Create a logger**

   The root default is **volatile** in-memory reliability. Destination adapters are imported from subpaths.

```ts title="audit.ts"
import { AuditLogger } from 'logbun';
import { BunSQLiteAdapter } from 'logbun/adapters/bun-sqlite';

const audit = new AuditLogger({
  namespace: 'my-app',
  adapter: new BunSQLiteAdapter({ path: '.logbun/audit.db' }),
});
```

   `BunSQLiteAdapter` uses `bun:sqlite`. It only runs on Bun. On Node or Deno, supply a Turso, ClickHouse, or custom `IAdapter` instead.

3. **Wait for bootstrap**

```ts
await audit.ready;
```

   `ready` never rejects. Bootstrap failure sets `audit.degraded` and emits `bootstrap_fail` / `degraded`. Logs accepted before `ready` sit in a **volatile** pre-ready buffer even if you later set `mode: 'durable'`.

4. **Emit an event**

```ts
audit.fire('user.created', { actorId: 'u1', tenantId: 't1' });
await audit.fireAsync('user.updated', { actorId: 'u1', tenantId: 't1' });
```

   `fire()` never throws. `fireAsync()` waits until admission (journal append in durable mode) and may reject.

5. **Flush and shut down**

```ts
await audit.flush();
await audit.shutdown();
```

   `flush()` drains RAM queues into the destination. Request-scoped volatile hosts that need delivery before the isolate exits should `await fireAsync(...); await flush()`.

Query the same destination:

```ts
const page = await audit.query({
  tenantId: 't1',
  pagination: { limit: 50 },
});
console.log(page.logs.length, page.nextCursor);
```

Default page size is 50, clamped to `[1, maxQueryLimit]` (default cap 500). Rows are newest-first by UUIDv7 `id`.

:::caution
This default is volatile. Process death can lose queued work. For production, set `mode: 'durable'` with `FileReliabilityAdapter` or `CloudflareReliabilityAdapter`. See [Durability](/concepts/durability).
:::

## Next

- [Installation](/installation) — exports, peers, runtimes
- [Bun](/guides/bun) / [Node](/guides/node) / [Deno](/guides/deno) / [Cloudflare](/guides/cloudflare)
- [Production](/guides/production) — replica isolation, maintenance, alerting

Source: https://logbun-docs.abshahin.workers.dev/get-started/index.mdx
