<?php
class log {
	public static function write($s, $file = 'php_error.php') {
		$time = date('Y-m-d H:i:s', $_ENV['_time']);
		$ip = $_ENV['_ip'];
		$url = self::to_str($_SERVER['REQUEST_URI']);
		$s = self::to_str($s);
		self::write_log('<?php exit;?>'."	$time	$ip	$url	$s	\r\n", $file);
		return TRUE;
	}
	public static function write_mini($s, $file = 'logs.php') {
		$time = date('Y-m-d H:i:s', $_ENV['_time']);
		$s = self::to_str($s);
		self::write_log('<?php exit;?>'."	$time	$s	\r\n", $file);
		return TRUE;
	}
	public static function to_str($s) {
		return str_replace(array("\r\n", "\r", "\n", "\t"), ' ', $s);
	}
	public static function write_log($s, $file) {
		$logfile = LOG_PATH.$file;
		try{
			$fp = fopen($logfile, 'ab+');
			if(!$fp) {
				throw new Exception("写入日志失败，文件 $file 不可写或空间已满。");
			}
			fwrite($fp, $s);
			fclose($fp);
		}catch(Exception $e) {}
		return TRUE;
	}
}
?>
