feat: support configurable log rotation strategies #8975

Open
opened 2026-02-16 18:11:18 -05:00 by yindo · 1 comment
Owner

Originally created by @Haoping-Xiao on GitHub (Feb 10, 2026).

Originally assigned to: @thdxr on GitHub.

Feature Request

Problem

Currently, Log.init creates a new log file on every startup (timestamped filename like 2026-02-10T142345.log). For long-running sessions or server deployments, this means:

  • Logs from the same day are split across multiple files
  • No way to customize the log directory
  • Cleanup is based on file count, not time-based retention

Proposed Solution

Introduce a rotate option to Log.Options with pluggable strategies:

  • startup (default) — current behavior, one file per startup, retain N files
  • daily — one file per day (opencode-YYYY-MM-DD.log), same-day restarts append, retain N days

Also add an optional path field to override the default log directory.

Both are controlled via environment variables:

  • OPENCODE_LOG_PATH — custom log directory
  • OPENCODE_LOG_ROTATE=daily — enable daily rotation
  • OPENCODE_LOG_RETENTION=N — retention count

Why

Useful for server deployments on cloud: you can customize the log path to integrate with cloud provider log systems (e.g., CloudWatch, Cloud Logging) for easier log collection and querying.

Originally created by @Haoping-Xiao on GitHub (Feb 10, 2026). Originally assigned to: @thdxr on GitHub. ### Feature Request **Problem** Currently, `Log.init` creates a new log file on every startup (timestamped filename like `2026-02-10T142345.log`). For long-running sessions or server deployments, this means: - Logs from the same day are split across multiple files - No way to customize the log directory - Cleanup is based on file count, not time-based retention **Proposed Solution** Introduce a `rotate` option to `Log.Options` with pluggable strategies: - `startup` (default) — current behavior, one file per startup, retain N files - `daily` — one file per day (`opencode-YYYY-MM-DD.log`), same-day restarts append, retain N days Also add an optional `path` field to override the default log directory. Both are controlled via environment variables: - `OPENCODE_LOG_PATH` — custom log directory - `OPENCODE_LOG_ROTATE=daily` — enable daily rotation - `OPENCODE_LOG_RETENTION=N` — retention count **Why** Useful for server deployments on cloud: you can customize the log path to integrate with cloud provider log systems (e.g., CloudWatch, Cloud Logging) for easier log collection and querying.
Author
Owner

@github-actions[bot] commented on GitHub (Feb 10, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #8968: [FEATURE]: Support OPENCODE_CACHE_DIR and OPENCODE_LOG_DIR for full isolation

Note that #8968 already includes an extended PR (#8963) that covers configurable log directories via OPENCODE_LOG_DIR. While this issue (#12960) focuses on rotation strategies (which is complementary), you may want to coordinate with the existing PR to ensure they work well together.

@github-actions[bot] commented on GitHub (Feb 10, 2026): This issue might be a duplicate of existing issues. Please check: - #8968: [FEATURE]: Support OPENCODE_CACHE_DIR and OPENCODE_LOG_DIR for full isolation Note that #8968 already includes an extended PR (#8963) that covers configurable log directories via `OPENCODE_LOG_DIR`. While this issue (#12960) focuses on rotation strategies (which is complementary), you may want to coordinate with the existing PR to ensure they work well together.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#8975