看了一下源码,有些地方疑惑,请解答。
static function write($message,$level=self::ERR,$type='',$destination='') {
if(!self::$storage){
$type = $type?:C('LOG_TYPE');
$class = 'Think\\Log\\Driver\\'. ucwords($type);
self::$storage = new $class();
}
if(empty($destination))
$destination = C('LOG_PATH').date('y_m_d').'.log';
self::$storage->write("{$level}: {$message}", $destination);
}这是TP的Log.class.php我在看了一下,C('LOG_PATH')的值是RUNTIME_PATH/Logs/
所以我在默认没有传递$destination的时候日志是指向默认的日志目录
此时调用 File.class.php 参数$destination为上面的值
public function write($log,$destination='') {
$now = date($this->config['log_time_format']);
if(empty($destination))
$destination = $this->config['log_path'].date('y_m_d').'.log';
if(!is_dir($this->config['log_path'])) {
mkdir($this->config['log_path'],0755,true);
}
//检测日志文件大小,超过配置大小则备份日志文件重新生成
if(is_file($destination) && floor($this->config['log_file_size']) <= filesize($destination) )
rename($destination,dirname($destination).'/'.time().'-'.basename($destination));
error_log("[{$now}] ".$_SERVER['REMOTE_ADDR'].' '.$_SERVER['REQUEST_URI']."\r\n{$log}\r\n", 3,$destination);
}进入write函数,$destination已经有值了,File.class.php在初始化的时候log_path是空的,所以根本不会创建$destination的文件夹。我的日志一直记录不成功,估计就是以上的原因。不知道是我哪里疏忽了还是框架的代码那边有些问题。请指教!
最佳答案