Skip to content

Commit 04eb616

Browse files
Added log cleanup, v3.6.4
Co-authored-by: baicaizhale <baicaizhale@users.noreply.github.com>
1 parent 0d4dda6 commit 04eb616

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

src/main/java/org/YanPl/manager/CLIManager.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public CLIManager(FancyHelper plugin) {
8888
loadYoloModePlayers();
8989
startTimeoutTask();
9090
startThinkingTask();
91+
startLogCleanupTask();
9192
}
9293

9394
public void loadAgreedPlayers() {
@@ -212,6 +213,48 @@ public void run() {
212213
}
213214
}.runTaskTimer(plugin, 20L * 60, 20L * 60); // 每分钟检查一次
214215
}
216+
217+
/**
218+
* 启动日志清理任务,定期删除超过配置天数的日志文件
219+
*/
220+
private void startLogCleanupTask() {
221+
new BukkitRunnable() {
222+
@Override
223+
public void run() {
224+
try {
225+
Path logDir = plugin.getDataFolder().toPath().resolve("logs");
226+
if (!Files.exists(logDir)) {
227+
return;
228+
}
229+
230+
int retentionDays = plugin.getConfigManager().getConfig().getInt("settings.log_retention_days", 15);
231+
long cutoffTime = System.currentTimeMillis() - (retentionDays * 24 * 60 * 60 * 1000L);
232+
233+
Files.list(logDir)
234+
.filter(path -> path.toString().endsWith(".log"))
235+
.filter(path -> {
236+
try {
237+
return Files.getLastModifiedTime(path).toMillis() < cutoffTime;
238+
} catch (IOException e) {
239+
return false;
240+
}
241+
})
242+
.forEach(path -> {
243+
try {
244+
Files.delete(path);
245+
if (plugin.getConfigManager().isDebug()) {
246+
plugin.getLogger().info("[CLI] 已删除过期日志文件: " + path.getFileName());
247+
}
248+
} catch (IOException e) {
249+
plugin.getLogger().warning("[CLI] 删除日志文件失败: " + path.getFileName() + " - " + e.getMessage());
250+
}
251+
});
252+
} catch (IOException e) {
253+
plugin.getLogger().warning("[CLI] 日志清理任务出错: " + e.getMessage());
254+
}
255+
}
256+
}.runTaskTimerAsynchronously(plugin, 0L, 20L * 60 * 60); // 每小时检查一次
257+
}
215258

216259
/**
217260
* 启动 AI 思考状态显示任务

src/main/resources/config.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# 配置版本,请勿修改
2-
version: 3.6.3
2+
version: 3.6.4
33

44
# 插件设置
55
settings:
@@ -35,6 +35,8 @@ settings:
3535
similarity_threshold: 0.95
3636
# 单次对话中连续调用工具的最大次数 (防止 AI 陷入逻辑循环或过度消耗)
3737
max_chain_count: 30
38+
# 日志保留天数,超过此天数的日志将被自动删除
39+
log_retention_days: 15
3840
# YOLO 模式下需要手动确认的风险命令列表(匹配前缀)
3941
yolo_risk_commands:
4042
- op

src/main/resources/plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: FancyHelper
2-
version: 3.6.3
2+
version: 3.6.4
33
main: org.YanPl.FancyHelper
44
api-version: '1.18'
55
softdepend: [ProtocolLib]

0 commit comments

Comments
 (0)