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);