-
Notifications
You must be signed in to change notification settings - Fork 6.3k
fix: prevent log file deletion when using --log-level DEBUG #6641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
fix: prevent log file deletion when using --log-level DEBUG #6641
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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! |
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