fix: prevent log file deletion when using --log-level DEBUG#6641
fix: prevent log file deletion when using --log-level DEBUG#6641AungMyoKyaw wants to merge 2 commits intoanomalyco:devfrom
Conversation
The init() function was calling cleanup() before creating new log file, which caused cleanup logic to delete existing log files including one from a previous run. Move cleanup() call to after new log file is created and truncated to ensure current log is never deleted during initialization. Fixes anomalyco#6583
The init() function was calling cleanup() before creating new log file, which caused cleanup logic to delete existing log files including one from a previous run. Move cleanup() call to after new log file is created and truncated to ensure current log is never deleted during initialization. Added test case to verify log preservation across reinitializations. Fixes anomalyco#6583
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where the --log-level DEBUG flag caused existing log files to be deleted. The fix reorders operations in the Log.init() function to ensure the new log file is created before running the cleanup routine that deletes old log files.
Key Changes:
- Moved
cleanup()call from before log file creation (line 60) to after (line 73) - Added comprehensive tests to verify log file preservation and rotation behavior
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 12 comments.
| File | Description |
|---|---|
packages/opencode/src/util/log.ts |
Relocated cleanup call to execute after new log file initialization, preventing deletion of the current log file |
packages/opencode/test/util/log.test.ts |
Added two test cases to verify log file preservation during reinitialization and proper log rotation behavior |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Hi @AungMyoKyaw! I ran into the same issue and did some investigation. I opened #7245 which addresses this with a similar approach (awaiting cleanup), but also adds Happy to coordinate if it makes sense to merge efforts! |
00637c0 to
71e0ba2
Compare
f1ae801 to
08fa7f7
Compare
|
Closing this pull request because it has had no updates for more than 60 days. If you plan to continue working on it, feel free to reopen or open a new PR. |
Summary
Changes
packages/opencode/src/util/log.tsto reorder initializationRoot Cause
The
init()function was callingcleanup(Global.Path.log)before setting up new log file. This caused the cleanup logic to delete log files including ones created in a previous run, because the new file path wasn't set yet when cleanup ran.Fix Details
By moving the
cleanup()call to execute after the new log file is created, initialized withfs.truncate(), and the writer is configured:Testing
Manual testing confirms this resolves issue #6583:
opencode→ Creates log file2026-01-01T152627.logopencode --log-level DEBUG→ Previous log is PRESERVED ✅Fixes #6583