From 728134a0d577c82a4e071193bc1c124d1f356309 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 2 Mar 2018 14:42:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=97=A5=E5=BF=97=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0max=5Ffiles=E5=8F=82=E6=95=B0=E9=85=8D=E7=BD=AE=20?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=B8=85=E7=90=86=E5=A4=9A=E4=BD=99=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/log/driver/File.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/library/think/log/driver/File.php b/library/think/log/driver/File.php index 4036cc44..6c61a9a1 100644 --- a/library/think/log/driver/File.php +++ b/library/think/log/driver/File.php @@ -25,6 +25,7 @@ class File 'file_size' => 2097152, 'path' => LOG_PATH, 'apart_level' => [], + 'max_files' => 0, ]; protected $writed = []; @@ -48,8 +49,20 @@ class File if ($this->config['single']) { $destination = $this->config['path'] . 'single.log'; } else { - $cli = IS_CLI ? '_cli' : ''; - $destination = $this->config['path'] . date('Ym') . DS . date('d') . $cli . '.log'; + $cli = IS_CLI ? '_cli' : ''; + + if ($this->config['max_files']) { + $filename = date('Ymd') . $cli . '.log'; + $files = glob($this->config['path'] . '*.log'); + + if (count($files) > $this->config['max_files']) { + unlink($files[0]); + } + } else { + $filename = date('Ym') . '/' . date('d') . $cli . '.log'; + } + + $destination = $this->config['path'] . $filename; } $path = dirname($destination);