From 28e39b4b38a051acfb0a023696f9f7947cc95bba Mon Sep 17 00:00:00 2001 From: laojiang8090 <132125160+laojiang8090@users.noreply.github.com> Date: Thu, 5 Dec 2024 19:27:04 +0800 Subject: [PATCH] Update File.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 当设置了最大文件数时,可以优先删除最先修改的问题 --- src/think/log/driver/File.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/think/log/driver/File.php b/src/think/log/driver/File.php index 26c0f99a14..e09dd43dbb 100644 --- a/src/think/log/driver/File.php +++ b/src/think/log/driver/File.php @@ -140,6 +140,9 @@ protected function getMasterLogFile(): string try { if (count($files) > $this->config['max_files']) { set_error_handler(function ($errno, $errstr, $errfile, $errline) {}); + usort($files, function($a, $b) { + return filemtime($a) - filemtime($b); // 按修改时间升序排序 + }); unlink($files[0]); restore_error_handler(); }