static function write($message, $level = self::ERR, $destination = '', $type = 3, $extra = '')
{
$config_obj = Yaf_Registry::get("config");
$log_config = $config_obj->log->toArray();
$now = date(self::$format);
$type = $type ? $type : 3;
$log_config['record'] = isset($log_config['record']) ? $log_config['record'] : false;
if (self::FILE == $type) {
// 文件方式记录日志
if (empty($destination)) {
if ($log_config['record']) {
if (!is_dir($log_config['dir'])) {
mkdir($log_config['dir'], 0777, true);
}
if (!is_dir($log_config['dir'] . '/' . date('Ymd'))) {
mkdir($log_config['dir'] . '/' . date('Ymd'), 0777, true);
}
$destination = $log_config['dir'] . '/' . date('Ymd') . '/' . date('y_m_d') . '.log';
} else {
if (!is_dir(MYPATH . '/logs/')) {
mkdir(MYPATH . '/logs/', 0777, true);
}
if (!is_dir(MYPATH . '/logs' . '/' . date('Ymd'))) {
mkdir(MYPATH . '/logs' . '/' . date('Ymd'), 0777, true);
}
$destination = MYPATH . '/logs/' . date('Ymd') . '/' . date('y_m_d') . '.log';
}
}
//检测日志文件大小,超过配置大小则备份日志文件重新生成
if (is_file($destination) && floor('2097152') <= filesize($destination)) {
rename($destination, dirname($destination) . '/' . time() . '-' . basename($destination));
}
} else {
$destination = $destination ? $destination : 'mubiao';
$extra = $extra ? $extra : '额外信息';
}
error_log("{$now} {$level}: {$message}\r\n", $type, $destination, $extra);
if ($log_config['record']) {
self::append($destination, "{$now} {$level}: {$message}\r\n", $type);
}
//clearstatcache();
}