Write auth's logs as the estate's log line (AHT-204) #189

Merged
merge-queue merged 2 commits from aht-204-logline into main 2026-11-26 14:06:16 -08:00
Owner

Part of AHT-204, one log line across the estate.

Before: auth logged free text with no time, such as console.error("[/api/auth/exchange/k8s] unexpected:", e) or console.warn("[/api/auth/device/token] minted:", JSON.stringify({...})), plus Hono's logger() access lines (<-- GET /path, --> GET /path 200 3ms). Error objects and upstream bodies went out unmasked.

After: every line is a romaine-life/logline line on stdout, through src/log.ts:

2026-11-26T14:02:11.408-08:00 pid=1 info device token minted subject=... device=nelsonlaptop role=service exp=1795729490
2026-11-26T14:02:11.410-08:00 pid=1 info request method=POST path=/api/auth/device/token status=200 ms=14
  • Message and fields: each message is fixed text and what varies goes in fields. Fields that are undefined are left out, as JSON.stringify left them out before.
  • Access log: requestLog() replaces Hono's logger() with one request line per answered request (method, path, status, ms). The path is the URL path alone, never the query, because a query can carry a sign-in code, state or device code. A 5xx is logged at error.
  • Credentials: no token, code, cookie, certificate or Authorization value is passed to the log. I checked each call. Error text (stack included), upstream bodies (tank grant, Better Auth's sign-in answer) and values the caller supplies (device attempt fields, azure-access reason) go through outside/errorText, which apply logline's redact and cap the text at 4 KiB. A sign-in response that has no url is logged by its keys only.
  • Better Auth: its own logger option goes through the same writer (betterAuthLogger).
  • Levels: successful mints and audit events (device enroll, tokens, azure-access decisions, machine grants, test-slot approvals) move from warn to info. Refusals stay warn and failures error.
  • Package: @romaine-life/logline 0.1.4 comes from Forgejo's npm registry through a new .npmrc, pinned exactly. The Dockerfile copies .npmrc and mounts FORGEJO_PACKAGES_TOKEN (the BuildKit secret image.mjs passes) for both npm ci runs. A types file, src/logline.d.ts, covers the untyped module.
  • Also changed: src/self-test.ts and oauth-clients.ts use the same writer. README and metrics comments now name the new lines.

Not changed: @better-auth/oauth-provider logs two startup warnings (Please ensure '/.well-known/...' exists) through better-auth core's module-level logger, which ignores the logger option. Those two still appear in Better Auth's own format.

Test: src/log.test.ts captures stdout, reads every line back with logline's parse, and covers the fields, masking, the cap, the request line (no query, 5xx at error) and Better Auth's lines. npm test (203 pass), npm run lint and ci-check passed.

🤖 Generated with Claude Code

Part of [AHT-204](https://openproject.home.romaine.life/wp/AHT-204), one log line across the estate. **Before:** auth logged free text with no time, such as `console.error("[/api/auth/exchange/k8s] unexpected:", e)` or `console.warn("[/api/auth/device/token] minted:", JSON.stringify({...}))`, plus Hono's `logger()` access lines (`<-- GET /path`, `--> GET /path 200 3ms`). Error objects and upstream bodies went out unmasked. **After:** every line is a [romaine-life/logline](https://forgejo.romaine.life/romaine-life/logline) line on stdout, through `src/log.ts`: ```text 2026-11-26T14:02:11.408-08:00 pid=1 info device token minted subject=... device=nelsonlaptop role=service exp=1795729490 2026-11-26T14:02:11.410-08:00 pid=1 info request method=POST path=/api/auth/device/token status=200 ms=14 ``` - **Message and fields:** each message is fixed text and what varies goes in fields. Fields that are `undefined` are left out, as `JSON.stringify` left them out before. - **Access log:** `requestLog()` replaces Hono's `logger()` with one `request` line per answered request (method, path, status, ms). The path is the URL path alone, never the query, because a query can carry a sign-in code, state or device code. A 5xx is logged at error. - **Credentials:** no token, code, cookie, certificate or Authorization value is passed to the log. I checked each call. Error text (stack included), upstream bodies (tank grant, Better Auth's sign-in answer) and values the caller supplies (device attempt fields, azure-access reason) go through `outside`/`errorText`, which apply logline's `redact` and cap the text at 4 KiB. A sign-in response that has no url is logged by its keys only. - **Better Auth:** its own logger option goes through the same writer (`betterAuthLogger`). - **Levels:** successful mints and audit events (device enroll, tokens, azure-access decisions, machine grants, test-slot approvals) move from `warn` to `info`. Refusals stay `warn` and failures `error`. - **Package:** `@romaine-life/logline` 0.1.4 comes from Forgejo's npm registry through a new `.npmrc`, pinned exactly. The Dockerfile copies `.npmrc` and mounts `FORGEJO_PACKAGES_TOKEN` (the BuildKit secret `image.mjs` passes) for both `npm ci` runs. A types file, `src/logline.d.ts`, covers the untyped module. - **Also changed:** `src/self-test.ts` and `oauth-clients.ts` use the same writer. README and metrics comments now name the new lines. **Not changed:** `@better-auth/oauth-provider` logs two startup warnings (`Please ensure '/.well-known/...' exists`) through better-auth core's module-level logger, which ignores the `logger` option. Those two still appear in Better Auth's own format. **Test:** `src/log.test.ts` captures stdout, reads every line back with logline's `parse`, and covers the fields, masking, the cap, the request line (no query, 5xx at error) and Better Auth's lines. `npm test` (203 pass), `npm run lint` and `ci-check` passed. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Every console.log/warn/error and Hono's logger() access log become
romaine-life/logline lines on stdout (src/log.ts): a fixed message and
key=value fields, the time with its zone and the pid. One request line per
answered request (method, path without its query, status, ms; a 5xx at
error). Error text, upstream bodies and caller-supplied values are masked
with logline's redact and capped; no token, code, cookie or Authorization
value is passed to the log. Successful mints and audit events move from warn
to info; refusals stay warn, failures error.

@romaine-life/logline 0.1.4 comes from Forgejo's npm registry through
.npmrc, pinned exactly; the Dockerfile copies .npmrc and mounts
FORGEJO_PACKAGES_TOKEN for npm ci.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Route Better Auth's own log lines through logline (AHT-204)
All checks were successful
Suite go / check-services (pull_request) Has been skipped
Suite default / check-rules (pull_request) Has been skipped
Suite release / scope (pull_request) Successful in 7s
Suite tofu / apply (pull_request) Has been skipped
Suite release / module (pull_request) Has been skipped
Suite release / reserve (pull_request) Has been skipped
Suite release / home-sync (pull_request) Has been skipped
Suite release / dispatch (pull_request) Has been skipped
Suite release / deploy-image (pull_request) Has been skipped
Suite tofu / scope (pull_request) Successful in 6s
Suite go / check-format (pull_request) Has been skipped
Suite web-app / check-image (pull_request) Has been skipped
Suite tofu / check-plan (pull_request) Has been skipped
Suite release / build (go, ubuntu-latest) (, go, false, ubuntu-latest, , go) (pull_request) Has been skipped
Suite release / finalize (pull_request) Has been skipped
Suite release / publish (pull_request) Has been skipped
Suite web-app / publish-static (pull_request) Has been skipped
Suite web-app / publish (pull_request) Has been skipped
Suite default / check-fetches (pull_request) Successful in 5s
Suite tofu / reused-checks (pull_request) Successful in 6s
Suite go / check-test-linux (pull_request) Successful in 7s
Suite web-app / reused-checks (pull_request) Successful in 4s
merge-queue landed on main
Suite default / reused-checks (pull_request) Successful in 5s
Suite release / check-build (go, ubuntu-latest) (, go, false, ubuntu-latest, , go) (pull_request) Successful in 18s
Suite go / check-test-windows (pull_request) Successful in 44s
Suite go / reused-checks (pull_request) Successful in 4s
Suite web-app / check-test (.) (pull_request) Successful in 51s
Suite release / check-package (pull_request) Successful in 43s
Suite release / reused-checks (pull_request) Successful in 4s
905e1b8ca6
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
merge-queue deleted branch aht-204-logline 2026-11-26 14:06:16 -08:00
Sign in to join this conversation.
No description provided.