> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bijection.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Logs

Every line a function logs (`console.debug`, `console.info`, `console.log`,
`console.warn`, `console.error`) becomes a fact in the system table
[`sys.logs`](https://docs.bijection.com/database/system-tables), after the execution settles, whether it
committed or refused. A log line is read like any other fact, with the read
verbs, and is governed by labels and grants like any other fact: each line
carries the label its execution ran at, so a reader sees only the lines its
label clears.

Each line holds:

* `execution`: the run it belongs to. Every line of one run shares it.
* `line`: its position in the run, from 0.
* `function`: the tree path of the function that ran.
* `component`: the logging function's component path (empty for the Root).
* `level`: `debug`, `info`, `log`, `warn` or `error`.
* `message`: the logged values, joined by spaces.
* `code` and `reason`: the refusal code and reason the run ended with (a host
  code such as `Conflict` or `Forbidden`, an app code from the function's
  `refuses`, or `Failed`), or `null` when it ended ok.
* `at`: the instant it was logged.
* `version`: the line's commit-order cursor (`ctx.page(sys.logs.by("version"), { size, cursor })`).

Lines are kept for 14 days. Logs are not returned to the caller of a
function: read them from `sys.logs`.

## Read logs from the CLI

Read a bounded selection of `sys.logs`, newest first:

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
bijection list sys.logs --by at --descending --first 50
bijection list sys.logs --where function=orders.place --by at --descending --first 200
bijection list sys.logs --under access.tenant/acme --by at --descending --first 50
bijection watch sys.logs
```

`bijection dev` tails the same lines on its own output.

## Read logs from code

A query reads `sys.logs` like any table, newest first and bounded:

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { query, role, sys, t } from "@bijectionhq/bijection";

// The role that may read logs; grant it to your operators.
export const operators = role({});

export const recent = query({ allow: [operators], args: { site: t.string } }, (ctx, { site }) =>
  ctx.list(sys.logs.where({ site }).by("at").descending().first(50)),
);

export const refusals = query({ allow: [operators], args: { fn: t.string } }, async (ctx, { fn }) =>
  (await ctx.list(sys.logs.where({ site: fn }).by("at").descending().first(100)))
    .filter((line) => line.code !== null),
);
```

`sys.logs` is read-only to the six writes: a data write to it refuses
`Disallowed` (`SysReadOnly`).

## Export logs

To send logs to an external service, place a
[log export](https://docs.bijection.com/operate/observability/log-export.md) installation. It reads the
lines its label clears from `sys.logs` and delivers them in batches to an
OpenTelemetry receiver or a signed webhook.

## Find a request's logs

When a call fails, its refusal names the request. Every line of that run
shares one `execution`, so read its lines with
`bijection list sys.logs --where function=<path> --first 50` and match the `execution`, or filter
`sys.logs` in a query.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.