PHP Fatal error: Uncaught think\exception\ErrorException: rename(/data/www/houduan_internet_hospital_data/runtime/log/202309/27.log,/data/www/houduan_internet_hospital_data/runtime/log/202309/1695756888-27.log): No such file or directory in /data/www/houduan_internet_hospital_data/thinkphp/library/think/log/driver/File.php:53Stack trace:#0 [internal function]: think\Error::appError(2, 'rename(/data/ww...', '/data/www/houdu...', 53, Array)#1 /data/www/houduan_internet_hospital_data/thinkphp/library/think/log/driver/File.php(53): rename('/data/www/houdu...', '/data/www/houdu...')#2 /data/www/houduan_internet_hospital_data/thinkphp/library/think/Log.php(157): think\log\driver\File->save(Array)#3 /data/www/houduan_internet_hospital_data/thinkphp/library/think/Error.php(84): think\Log::save()#4 [internal function]: think\Error::appShutdown()#5 {main} thrown in /data/www/houduan_internet_hospital_data/thinkphp/library/think/log/driver/File.php on line 53
在php_error.log日志文件中有大量信息堆积
追溯代码到文件 \thinkphp\library\think\log\driver\File.php
代码如下:
public function save(array $log = [], $depr = true)
{
$now = date($this->config['time_format']);
$destination = $this->config['path'] . date('Ym') . DS . date('d') . '.log';
$path = dirname($destination);
!is_dir($path) && mkdir($path, 0755, true);
//检测日志文件大小,超过配置大小则备份日志文件重新生成
if (is_file($destination) && floor($this->config['file_size']) <= filesize($destination)) {
rename($destination, dirname($destination) . DS . $_SERVER['REQUEST_TIME'] . '-' . basename($destination));
}
}
在rename前面添加@符号,如下:
@rename($destination, dirname($destination) . DS . $_SERVER['REQUEST_TIME'] . '-' . basename($destination));
即可解决报错问题