Logging

crust writes the story of a run itself: one JSON object per line, on disk, with no print statements from your code. Every launch records the app's lifecycle, each window's life, every invoke with its duration and outcome, page console output and uncaught errors, and every platform refusal — enough to answer "why did this invoke fail" after the fact.

Where the files are

The files sit under the app's own data root; on macOS that is ~/Library/Application Support/<app.id>.

~/Library/Application Support/<app.id>/logs/app.jsonl      live file
~/Library/Application Support/<app.id>/logs/app.1.jsonl    one generation back, then .2, .3
~/Library/Application Support/<app.id>/logs/errors.jsonl   framework warn and above only

<app.id> is app.id from crust.config.ts, so two apps never share a directory. app.jsonl rotates when it reaches logging.maxBytes; the live file moves to app.1.jsonl, the previous .1 to .2, and the oldest generation is deleted last. errors.jsonl is the subset you attach to a bug report: it keeps framework and plugin warn and error only — page warnings stay in app.jsonl, so a page cannot rotate the triage file away — and rotates at the same size keeping one generation.

One line

{"ts":"2026-11-20T09:41:07.812Z","level":"info","source":"bridge","event":"bridge.invoke","msg":"os.info refused","window":"main","ns":"os","cmd":"info","durMs":0.42,"ok":false,"code":"forbidden","pid":4711,"seq":38}
fieldwhat it is
tsISO 8601 with milliseconds
leveltrace, debug, info, warn or error
sourcewhich part of the app wrote it: app, window, bridge, page, platform or plugin
eventa stable dotted name — app.ready, window.create, bridge.invoke, page.error
msgone human sentence
pidprocess id, so a dev restart's lines are separable
seqmonotonic per process, so ordering survives two lines with an equal timestamp

Source-specific fields are the reason the format exists:

eventfields
bridge.invokewindow, ns, cmd, durMs, ok, code (on failure), bytesIn, bytesOut
bridge.refusereason — origin, token or capability — plus window, ns, cmd
window.*label, width, height, visible; the record's event is window.create, window.close, window.focus or window.resize
app.*app, platform, arch, runtime, version, then counts only: windows, plugins, capabilities, grants
page.consoleconsoleLevel, args (serialised and truncated), url
page.errormessage, stack (first frames), url, line, col
platform.*api, code, detail — what a not-implemented refusal already carries

Filtering with tail

const { records } = await window.crust.invoke("logging", "tail", {
	level: "warn",
	source: "bridge",
	since: "2026-11-20T09:40:00.000Z",
	limit: 50,
});
// [{ ts, level, source, event, msg, … }, …]

tail reads the live file and answers parsed objects, not strings, so a field is a field rather than text to parse again. Every argument is optional and the filters combine: level keeps that level and above, source keeps one writer, since keeps lines from that instant on (an ISO 8601 timestamp or epoch milliseconds), and limit caps the answer. A line that is not valid JSON comes back with raw set instead of breaking the read, so one truncated write cannot hide the rest of the file.

A page reaches it like any namespace: once security.capabilities is present, that window label needs logging:tail in its grant.

What each record costs

The level is chosen by what a person needs, so the default is worth reading:

recordlevel
app.*, window.create/closeinfo — the run's shape: started, ready, window open, quit
bridge.invoke (success)debug — one line per call, and the firehose this flag exists for
bridge.invoke (failure)warn, or error for handler-error/not-implemented
bridge.refusewarn — a refusal is why the page did nothing, at every default
page.consolethe console method's own level
page.errorerror
platform.refuseerror

So info keeps the lifecycle and every refusal, and warn keeps the refusals and errors while silencing invokes and lifecycle. Invokes are the reason debug is a level away rather than on.

Raising the level

info is the default, in crust dev and in a built app. Anything quieter is dropped before it is written, so the file stays small. Four sources decide it, and the first one set wins:

  1. crust dev --log-level <level> — this run only.

  2. CRUST_LOG=<level> in the environment — a shell can set it once.

  3. logging.level in crust.config.ts:

    // crust.config.ts
    export default {
    	// …
    	logging: { level: "debug" },
    } satisfies CrustConfig;
    
  4. The default, info.

A bad value is refused rather than falling back: crust dev --log-level loud prints unknown log level "loud" — expected trace, debug, info, warn or error and exits 1, and an unrecognised CRUST_LOG says so once and leaves logging.level (or the default) in force.

debug adds the detail worth having while building — invocation boundaries and the page's own console.debug — and is what --log-level debug is for. A built app writes files and stays quiet unless you set console: true, which mirrors warn and error with the human one-line form. Under crust dev every level is mirrored, including debug, info and trace; the built-app console key does not do that.

The mirror follows severity: debug and info go to stdout, warn through console.warn and error to stderr. That keeps 2> meaningful — redirecting stderr to a file gives you what went wrong, not the whole conversation — and lets a terminal colour each line by its level.

What is never logged

A redaction pass runs over every field by name and over the message string, because a URL can carry a token in its query. A value that reaches a log line under one of those names is replaced with [redacted] before the line is appended, so it is never written and cannot be recovered from an archive.

Redacted names, at any depth of an object or array:

redactedkept
token, seed, secret, password, passphrasekeys, key
credential, authorization, cookiepublicKey, public_key
apiKey, api_key, privateKey, private_keykeyCount, shape
keychain, and any name ending in Token, Secret, Password or ApiKeyanything else not named after a secret

The list is deliberately curated. A bare key or keys is as often a lookup table as a credential, and redacting one deletes a field you meant to keep with nothing to recover it — that happened to a real app, which had to rename its field. So name a field after what it holds, not after a secret word: keys: ["a", "b"] is logged verbatim, while the same array under apiKey arrives as [redacted].

A plugin with no native half

A plugin declares the native half it needs as native: { requires, available }. At registration the runtime writes one error line naming every namespace whose adapter is missing — dialog, notification, shortcut, … — once per distinct set, before the first window opens. A compiled app whose platform adapters did not load therefore says so at startup, instead of answering null to a picker and installing nothing for a menu. Under crust dev the same line is usually absent, because the native halves are built from this checkout; in a bundle it is the first thing to read.

Seeing it while you work

crust dev streams each written record to the terminal, so the run you are watching prints its own lifecycle and refusals without a tail call or a file to open. It starts at info: lifecycle and refusals appear, while invokes — one line per call — appear only when you ask with crust dev --log-level debug (or CRUST_LOG=debug). To read the same events from a built app, call logging.tail or open app.jsonl; see the config reference for the block's defaults.