File tree Expand file tree Collapse file tree 3 files changed +47
-2
lines changed
Expand file tree Collapse file tree 3 files changed +47
-2
lines changed Original file line number Diff line number Diff 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 思考状态显示任务
Original file line number Diff line number Diff line change 11# 配置版本,请勿修改
2- version : 3.6.3
2+ version : 3.6.4
33
44# 插件设置
55settings :
@@ -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
Original file line number Diff line number Diff line change 11name : FancyHelper
2- version : 3.6.3
2+ version : 3.6.4
33main : org.YanPl.FancyHelper
44api-version : ' 1.18'
55softdepend : [ProtocolLib]
You can’t perform that action at this time.
0 commit comments