chore(maafw): 按历史记录保留天数清理 MFW 原生日志备份 - #640
Merged
qiyinxi merged 1 commit intoSep 9, 2026
Merged
Conversation
MaaFramework 把 debug/maafw.log 写到一定大小就整体挪成 debug/maafw.bak.<时间戳>.log 再开新的,但从不回收旧的,一个每天跑的项目 几天就能堆出几百 MB。每次运行的完整内容已经另存进历史记录的 *.maafw.log, 原地那些备份是纯冗余。 - 新增 clean_maafw_native_debug_logs(),随启动清理一并执行,判据沿用 Function/HistoryRetentionTime,设为「永久」时整轮弃权 - 只删 maafw.bak.*.log,正在写的 maafw.log 与其他调试文件不动 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
审查者指南本 PR 为 MFW 原生日志轮转备份增加了基于历史记录保留天数的启动时回收机制:按项目配置定位 debug 目录,仅删除过期备份,支持永久保留配置和逐文件失败容错,避免冗余日志无限占用磁盘。 MFW 原生日志备份启动时清理的时序图sequenceDiagram
participant Startup as BackgroundStartup
participant Config as Config
participant Project as MaaFWProject
participant Debug as DebugDirectory
participant Logger as Logger
Startup->>Config: clean_maafw_native_debug_logs()
Config->>Config: get(Function, HistoryRetentionTime)
alt HistoryRetentionTime == 0
Config->>Logger: info(permanent retention, skip cleanup)
else Retention enabled
loop Each MaaFW project
Config->>Project: get(Info, Path)
Config->>Debug: glob(maafw.bak.*.log)
loop Each rotated backup
alt Backup is expired
Config->>Debug: unlink(backup)
else Delete fails
Config->>Logger: warning(delete failure)
end
end
end
Config->>Logger: success(deleted backup count)
end
文件级变更
提示和命令与 Sourcery 交互
自定义使用体验访问你的控制面板以:
获取帮助Original review guide in EnglishReviewer's Guide本 PR 为 MFW 原生日志轮转备份增加了基于历史记录保留天数的启动时回收机制:按项目配置定位 debug 目录,仅删除过期备份,支持永久保留配置和逐文件失败容错,避免冗余日志无限占用磁盘。 Sequence diagram for startup cleanup of MFW native log backupssequenceDiagram
participant Startup as BackgroundStartup
participant Config as Config
participant Project as MaaFWProject
participant Debug as DebugDirectory
participant Logger as Logger
Startup->>Config: clean_maafw_native_debug_logs()
Config->>Config: get(Function, HistoryRetentionTime)
alt HistoryRetentionTime == 0
Config->>Logger: info(permanent retention, skip cleanup)
else Retention enabled
loop Each MaaFW project
Config->>Project: get(Info, Path)
Config->>Debug: glob(maafw.bak.*.log)
loop Each rotated backup
alt Backup is expired
Config->>Debug: unlink(backup)
else Delete fails
Config->>Logger: warning(delete failure)
end
end
end
Config->>Logger: success(deleted backup count)
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MaaFramework 把
debug/maafw.log写到一定大小就整体挪成debug/maafw.bak.<时间戳>.log再开新的,但从不回收旧的。实测一个每天跑的 MaaEnd 项目四天堆了 15 个备份、385 MB,而这些内容每次运行都已经另存进历史记录的*.maafw.log,原地那份是纯冗余。clean_maafw_native_debug_logs(),随启动清理一并执行,保留时长沿用Function/HistoryRetentionTime,与旁边的clean_debug_diagnostics同一口径;设为「永久保留」时整轮弃权maafw.bak.*.log,正在写的maafw.log、go-service.log、debug/record/都不动;单个文件删失败只记 warning 不中断本地验证
python -m pytest tests/core tests/task -qpython -m pytest tests --collect-only -qruff check/ruff format --check(本 PR 新增的代码)main.py的 I001 与app/core/config.py的 format 差异在本分支基点上就已存在(拿git show HEAD:的原始文件复核过),且格式化涉及的最后一处在第 2948 行、本 PR 代码在 4293 行,未受影响,因此没有顺带格式化。按
tests/AGENTS.md,对应的边界测试只在本地运行,未随 PR 提交。🤖 Generated with Claude Code
Sourcery 摘要
通过在启动维护中加入基于保留策略的清理机制,防止 MaaFramework 原生调试日志备份无限累积。
改进:
杂项:
Original summary in English
Summary by Sourcery
Prevent MaaFramework native debug log backups from accumulating indefinitely by including their retention-based cleanup in startup maintenance.
Enhancements:
Chores: