From afd614e5639da18165ec5c14f3c0dc167d10394d Mon Sep 17 00:00:00 2001 From: augushong Date: Mon, 1 Jun 2026 20:28:25 +0800 Subject: [PATCH] =?UTF-8?q?feat(timer):=20ClearLog=20=E6=B8=85=E7=90=86?= =?UTF-8?q?=E5=A4=A9=E6=95=B0=E6=94=B9=E4=B8=BA=E4=BB=8E=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E8=AF=BB=E5=8F=96=EF=BC=8C=E6=94=AF=E6=8C=81=20env=20=E8=A6=86?= =?UTF-8?q?=E7=9B=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus --- .example.env | 4 ++++ config/timer.php | 5 +++++ extend/base/tools/controller/timer/ClearLogBase.php | 5 +++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/.example.env b/.example.env index c8e304f..b14df79 100644 --- a/.example.env +++ b/.example.env @@ -21,6 +21,10 @@ FIELDS_CACHE=false [LOG] CHANNEL=file +[TIMER] +# 清理日志保留天数(debug_log 表) +CLEAR_LOG_DAYS=3 + [LANG] default_lang=zh-cn diff --git a/config/timer.php b/config/timer.php index 0d451c2..302f4b4 100644 --- a/config/timer.php +++ b/config/timer.php @@ -1,5 +1,7 @@ 'normal', @@ -9,6 +11,9 @@ $config = [ 'keepalive_timeout' => 86400, // 连接多长时间不通讯就关闭 'connect_timeout' => 86400, // 连接超时时间 'timeout' => 86400, // 请求发出后等待响应的超时时间 + + // 清理日志保留天数(debug_log 表) + 'clear_log_days' => Env::get('timer.clear_log_days', 3), ]; return $config; diff --git a/extend/base/tools/controller/timer/ClearLogBase.php b/extend/base/tools/controller/timer/ClearLogBase.php index 50846b6..a8ec744 100644 --- a/extend/base/tools/controller/timer/ClearLogBase.php +++ b/extend/base/tools/controller/timer/ClearLogBase.php @@ -14,8 +14,9 @@ class ClearLogBase extends TimerController public function do() { - Log::debug('清除3天的日志'); - Db::name('debug_log')->where('create_time', '<', time() - 60 * 60 * 24 * 3)->delete(); + $days = (int) config('timer.clear_log_days', 3); + Log::debug('清除' . $days . '天的日志'); + Db::name('debug_log')->where('create_time', '<', time() - 60 * 60 * 24 * $days)->delete(); return 'success'; }