Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
- 代码清理 单源化各脚本专项重复的任务报告推送核心与 QQ/微信通知公共助手,并清理前后端死代码与直通包装组件,行为保持不变 by [@1w1w11w1](https://github.com/1w1w11w1)
- MAA专项 代理接管 MAA 配置时强制开启开始唤醒的账号切换开关,确保按用户配置的账号切号;用户未填写账号时仍不会切号 by [@1w1w11w1](https://github.com/1w1w11w1)
- MFW专项 进入项目配置页不再每次都要等一遍运行环境确认,开启自动更新时环境准备也提前到任务开始之前完成 by [@qiyinxi](https://github.com/qiyinxi)
- 日志清理 MFW 项目里 MaaFramework 轮转出的原生日志备份改为按历史记录的保留天数一并清理,不再无限堆积占用磁盘

### 移除

Expand Down
41 changes: 41 additions & 0 deletions app/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4290,6 +4290,47 @@ async def clean_debug_diagnostics(self) -> None:
if deleted_count:
logger.success(f"清理完成: {deleted_count} 个过期诊断文件")

async def clean_maafw_native_debug_logs(self) -> None:
"""清掉 MFW 项目里过期的 MaaFramework 原生日志备份。

MaaFramework 把 ``debug/maafw.log`` 写到一定大小就整体挪成
``debug/maafw.bak.<时间戳>.log`` 再开新的,但从不回收旧的——一个每天跑
的项目几天就能堆出几百 MB。每次运行的完整内容已经另存进历史记录的
``*.maafw.log``,所以这里只删备份,正在写的 ``maafw.log`` 不动。
保留时长沿用历史记录的保留天数设置。
"""

if self.get("Function", "HistoryRetentionTime") == 0:
logger.info("原生日志永久保留, 跳过 MFW 原生日志备份清理")
return

from app.models.config import MaaFWConfig

cutoff = time.time() - self.get("Function", "HistoryRetentionTime") * 86400
deleted_count = 0
for script_config in self.ScriptConfig.values():
if not isinstance(script_config, MaaFWConfig):
continue
project_path = str(script_config.get("Info", "Path") or "").strip()
if not project_path:
continue
debug_folder = Path(project_path) / "debug"
if not debug_folder.is_dir():
continue
# 备份文件名由 MaaFramework 决定,与 runner_task 里
# _iter_rotated_native_debug_logs 认的是同一套。
for file in debug_folder.glob("maafw.bak.*.log"):
try:
if file.stat().st_mtime >= cutoff:
continue
file.unlink()
except OSError as exc:
logger.warning(f"MFW 原生日志备份清理失败: {file} - {exc}")
continue
deleted_count += 1
if deleted_count:
logger.success(f"清理完成: {deleted_count} 个过期 MFW 原生日志备份")

async def clean_old_history(self):
"""删除超过用户设定天数的历史记录文件(基于目录日期)"""

Expand Down
1 change: 1 addition & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ async def initialize_background_services() -> None:
await Config.clean_old_history()
await Config.clean_maafw_agent_venvs()
await Config.clean_debug_diagnostics()
await Config.clean_maafw_native_debug_logs()

if IS_WINDOWS:
for adapter in ("app.MaaFW.ArknightWin32",):
Expand Down
3 changes: 2 additions & 1 deletion res/version.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
"日志清理 自动清理OCR图片 by [@HarcoChen](https://github.com/HarcoChen)",
"代码清理 单源化各脚本专项重复的任务报告推送核心与 QQ/微信通知公共助手,并清理前后端死代码与直通包装组件,行为保持不变 by [@1w1w11w1](https://github.com/1w1w11w1)",
"MAA专项 代理接管 MAA 配置时强制开启开始唤醒的账号切换开关,确保按用户配置的账号切号;用户未填写账号时仍不会切号 by [@1w1w11w1](https://github.com/1w1w11w1)",
"MFW专项 进入项目配置页不再每次都要等一遍运行环境确认,开启自动更新时环境准备也提前到任务开始之前完成 by [@qiyinxi](https://github.com/qiyinxi)"
"MFW专项 进入项目配置页不再每次都要等一遍运行环境确认,开启自动更新时环境准备也提前到任务开始之前完成 by [@qiyinxi](https://github.com/qiyinxi)",
"日志清理 MFW 项目里 MaaFramework 轮转出的原生日志备份改为按历史记录的保留天数一并清理,不再无限堆积占用磁盘"
],
"移除": [
"移除米游币获取任务,保留米游社各游戏签到。 by [@Lance0174](https://github.com/Lance0174)"
Expand Down
Loading