第50行由于目录权限是0755,如果有命令行执行在先生成了目录,后有网页访问执行代码生成的日志文件可能无法正确保存,导致json结果返回了但网页状态为500错误
linux环境中命令行执行者是root,网页是daemon
/**
* 日志写入接口
* @access public
* @param array $log 日志信息
* @return bool
*/
public function save(array $log = [])
{
$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);
$info = '';
foreach ($log as $type => $val) {
$level = '';
foreach ($val as $msg) {
if (!is_string($msg)) {
$msg = var_export($msg, true);
}
$level .= '[ ' . $type . ' ] ' . $msg . "\r\n";
}
if (in_array($type, $this->config['apart_level'])) {
// 独立记录的日志级别
$filename = $path . DS . date('d') . '_' . $type . $cli . '.log';
$this->write($level, $filename, true);
} else {
$info .= $level;
}
}
if ($info) {
return $this->write($info, $destination);
}
return true;
} 最佳答案