From be7a257e5f7746128ae6ad4d9d3ceaf12c448d62 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 14 Nov 2017 17:34:56 +0800 Subject: [PATCH] =?UTF-8?q?File=E6=97=A5=E5=BF=97=E9=A9=B1=E5=8A=A8?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0single=E5=8F=82=E6=95=B0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E8=AE=B0=E5=BD=95=E5=8D=95=E4=B8=AA=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/log/driver/File.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/library/think/log/driver/File.php b/library/think/log/driver/File.php index d82a5243..3bcff901 100644 --- a/library/think/log/driver/File.php +++ b/library/think/log/driver/File.php @@ -23,6 +23,7 @@ class File 'file_size' => 2097152, 'path' => LOG_PATH, 'apart_level' => [], + 'single' => false, ]; protected $writed = []; @@ -43,8 +44,13 @@ class File */ public function save(array $log = []) { - $cli = IS_CLI ? '_cli' : ''; - $destination = $this->config['path'] . date('Ym') . DS . date('d') . $cli . '.log'; + 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'; + } $path = dirname($destination); !is_dir($path) && mkdir($path, 0755, true); @@ -60,7 +66,11 @@ class File } if (in_array($type, $this->config['apart_level'])) { // 独立记录的日志级别 - $filename = $path . DS . date('d') . '_' . $type . $cli . '.log'; + if ($this->config['single']) { + $filename = $path . $type . '.log'; + } else { + $filename = $path . DS . date('d') . '_' . $type . $cli . '.log'; + } $this->write($level, $filename, true); } else { $info .= $level; @@ -75,7 +85,7 @@ class File protected function write($message, $destination, $apart = false) { //检测日志文件大小,超过配置大小则备份日志文件重新生成 - if (is_file($destination) && floor($this->config['file_size']) <= filesize($destination)) { + if (!$this->config['single'] && is_file($destination) && floor($this->config['file_size']) <= filesize($destination)) { rename($destination, dirname($destination) . DS . time() . '-' . basename($destination)); $this->writed[$destination] = false; }