[PR #12961] feat(opencode): add pluggable log rotation strategies #14452

Closed
opened 2026-02-16 18:19:14 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/12961

State: closed
Merged: No


Closes #12960

What

Adds pluggable write strategies to Log.init so log rotation behavior is configurable without changing default behavior.

Two strategies:

  • startup (default) — existing behavior, one file per startup, retain last 10 files
  • daily — one file per day (opencode-YYYY-MM-DD.log), same-day restarts append, retain 7 days by default

How

Log.Options gets two new optional fields:

path?: string    // custom log directory
rotate?: Rotate  // { kind: "startup" | "daily", retention?: number }

A writeStrategies record maps each kind to its init function. Adding a new strategy = add a type variant + a function. init() dispatches in one line:

return writeStrategies[options.rotate?.kind ?? "startup"](options)

Env vars for configuration (since Log.init runs before Config loads):

  • OPENCODE_LOG_PATH — override log directory
  • OPENCODE_LOG_ROTATE=daily — enable daily rotation
  • OPENCODE_LOG_RETENTION=14 — override retention count

Not passing anything = zero behavior change.

Verification

  • Ran bun run typecheck — passes
  • Tested startup strategy (default) — same file naming and cleanup as before
  • Tested OPENCODE_LOG_ROTATE=daily OPENCODE_LOG_PATH=/tmp/opencode-logs — generates opencode-2026-02-10.log, appends on restart
  • Tested retention cleanup with 10 dummy files + OPENCODE_LOG_RETENTION=3 — correctly keeps newest 3

Files changed

  • packages/opencode/src/util/log.ts — core changes
  • packages/opencode/src/index.ts — pass env vars to Log.init
  • packages/opencode/src/cli/cmd/tui/worker.ts — same
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/12961 **State:** closed **Merged:** No --- Closes #12960 ## What Adds pluggable write strategies to `Log.init` so log rotation behavior is configurable without changing default behavior. Two strategies: - **`startup`** (default) — existing behavior, one file per startup, retain last 10 files - **`daily`** — one file per day (`opencode-YYYY-MM-DD.log`), same-day restarts append, retain 7 days by default ## How `Log.Options` gets two new optional fields: ```ts path?: string // custom log directory rotate?: Rotate // { kind: "startup" | "daily", retention?: number } ``` A `writeStrategies` record maps each `kind` to its init function. Adding a new strategy = add a type variant + a function. `init()` dispatches in one line: ```ts return writeStrategies[options.rotate?.kind ?? "startup"](options) ``` Env vars for configuration (since Log.init runs before Config loads): - `OPENCODE_LOG_PATH` — override log directory - `OPENCODE_LOG_ROTATE=daily` — enable daily rotation - `OPENCODE_LOG_RETENTION=14` — override retention count Not passing anything = zero behavior change. ## Verification - Ran `bun run typecheck` — passes - Tested `startup` strategy (default) — same file naming and cleanup as before - Tested `OPENCODE_LOG_ROTATE=daily OPENCODE_LOG_PATH=/tmp/opencode-logs` — generates `opencode-2026-02-10.log`, appends on restart - Tested retention cleanup with 10 dummy files + `OPENCODE_LOG_RETENTION=3` — correctly keeps newest 3 ## Files changed - `packages/opencode/src/util/log.ts` — core changes - `packages/opencode/src/index.ts` — pass env vars to `Log.init` - `packages/opencode/src/cli/cmd/tui/worker.ts` — same
yindo added the pull-request label 2026-02-16 18:19:14 -05:00
yindo closed this issue 2026-02-16 18:19:14 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#14452