Skip to content

feat: support configurable log rotation strategies #12960

@Haoping-Xiao

Description

@Haoping-Xiao

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions