Skip to content

feat(opencode): add pluggable log rotation strategies#12966

Open
Haoping-Xiao wants to merge 7 commits intoanomalyco:devfrom
Haoping-Xiao:feat-log-rotate-v153
Open

feat(opencode): add pluggable log rotation strategies#12966
Haoping-Xiao wants to merge 7 commits intoanomalyco:devfrom
Haoping-Xiao:feat-log-rotate-v153

Conversation

@Haoping-Xiao
Copy link

@Haoping-Xiao Haoping-Xiao commented Feb 10, 2026

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

@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: support configurable log rotation strategies

1 participant