Skip to content

fix(ops): 为 openless.log 增加启动轮转#309

Merged
H-Chris233 merged 1 commit into
Open-Less:mainfrom
H-Chris233:fix/issue-303-log-rotation
May 7, 2026
Merged

fix(ops): 为 openless.log 增加启动轮转#309
H-Chris233 merged 1 commit into
Open-Less:mainfrom
H-Chris233:fix/issue-303-log-rotation

Conversation

@H-Chris233
Copy link
Copy Markdown
Collaborator

@H-Chris233 H-Chris233 commented May 7, 2026

User description

变更

  • 启动初始化日志前检查 openless.log 大小,超过 10 MiB 时轮转为 openless.log.1
  • 轮转失败不阻塞启动,但会输出 warning,便于在文件 logger 初始化前排查失败原因
  • 保持“导出错误日志”只导出当前 openless.log,不包含历史归档
  • 补充日志轮转边界单测:超限轮转、未超限不轮转、文件不存在不轮转

验证

  • cargo test --manifest-path src-tauri/Cargo.toml log_
  • cargo check --manifest-path src-tauri/Cargo.toml
  • git diff --check

Closes #303


PR Type

Enhancement, Bug fix


Description

  • Rotate openless.log on startup if > 10 MiB

  • Archive to openless.log.1, delete old archive

  • Move logger init to setup to avoid duplicate rotation

  • Add tests for rotation, small, and missing log


Diagram Walkthrough

flowchart LR
  A["App startup"] --> B["Check openless.log size"]
  B --> C{"Size > 10 MiB?"}
  C -- Yes --> D["Remove old archive openless.log.1"]
  D --> E["Rename current log to archive"]
  E --> F["Initialize file logger"]
  C -- No --> F
  F --> G["Append new logs"]
Loading

File Walkthrough

Relevant files
Enhancement
lib.rs
Implement startup log rotation to cap openless.log at 10 MiB

openless-all/app/src-tauri/src/lib.rs

  • Added constant LOG_ROTATE_LIMIT_BYTES (10 MiB)
  • Added rotate_log_if_too_large to archive oversized log
  • Called rotation in init_file_logger, warning on failure
  • Moved init_file_logger to setup closure after single‑instance check
  • Added three unit tests: oversized rotates, small skips, missing file
    is no‑op
+88/-4   

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8ef0d4b96e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread openless-all/app/src-tauri/src/lib.rs
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

PR Reviewer Guide 🔍

(Review updated until commit 275a11e)

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis ✅

303 - PR Code Verified

Compliant requirements:

  • 启动时按 10 MiB 阈值轮转 openless.logopenless.log.1
  • 轮转前会删除旧的 openless.log.1
  • 轮转失败不会阻塞启动,并会输出 warning
  • 已补充超限、未超限、文件不存在的单测

Requires further human verification:

  • 需要人工验证错误日志导出功能是否确实只包含当前 openless.log,且不会把 openless.log.1 一并打包
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ No major issues detected

Long-running tray installs can accumulate an unbounded openless.log. Startup now checks the current log after single-instance arbitration but before simplelog opens the file, then rotates files over 10 MiB to openless.log.1. Normal append logging resumes with a fresh current log and log export continues to copy only openless.log.

Rotation remains best-effort: startup continues if archive cleanup or rename fails, but stderr receives an explicit warning so the failure is diagnosable even before the file logger is initialized. Boundary tests cover oversized, small, and missing log files.

Constraint: Issue Open-Less#303 asks for a minimal startup size check with openless.log.1 archive.
Constraint: Duplicate macOS/Linux launches must exit before rotation so they cannot rename the owning instance's active log file.
Rejected: Add tracing-appender rolling support | new dependency and wider logging rewrite for a low-risk ops fix.
Rejected: Add platform-specific rotation-failure tests | brittle across Linux/macOS/Windows file locking semantics.
Confidence: high
Scope-risk: narrow
Directive: Keep export_error_log focused on openless.log; do not include rotated archives unless product explicitly asks for history export.
Directive: Keep log rotation best-effort; startup must continue even if archive cleanup or rename fails.
Tested: cargo test --manifest-path src-tauri/Cargo.toml log_
Tested: cargo check --manifest-path src-tauri/Cargo.toml
Tested: git diff --check
Not-tested: Manual startup rotation on Windows/macOS.
Related: Open-Less#303
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

Persistent review updated to latest commit 275a11e

@H-Chris233 H-Chris233 merged commit ed555fb into Open-Less:main May 7, 2026
5 checks passed
@H-Chris233 H-Chris233 deleted the fix/issue-303-log-rotation branch May 7, 2026 03:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ops] 日志文件无轮转 — openless.log 无限增长

1 participant