maxc1017 发表于 2017-3-3 12:47:34

php Exception

Class Exceptions extends Exception
{
/**
* 异常日志存储文件夹
* @public string
*/
//public $_Dir = '';
public $_Dir = LOG_DIR;
/**
* 异常日志文件命名规则
* @public string
* 可设置包含date函数的动态名字,如 'Exception_'.date('m-d').'.log'
*/
//public $_Filename = 'Error.log';
public $_Filename = LOG_FILENAME;
public function __construct($_Message=0, $_Code=0)
{
parent::__construct($_Message, $_Code);
}
public function __toString()
{
return date('')." [{$this->code}] {$this->message} IN {$this->file} on LINE {$this->line} - {$_SERVER['REQUEST_URI']}";
}
public function Log()
{
error_log($this->__toString()."\r\n", 3, $this->_Dir.$this->_Filename);
return $this;
}
public function View()
{
$_Code= "<html>\n<head>\n<title>错误</title>\n</head>\n<body>\n<div style='color:#ea0000;font-size:22px;font-weight:bold;'>%s 错误</div>\n".
"<hr><div style='color:#666;font-size:16px;background:#f6f6f6;padding:8px;line-height:25px'>\n".
"在访问 %s 时发生错误,错误信息如下:\n".
"<div style='font-size:14px;'>\n<li>文件: %s<br>\n<li>行数: %s<br>\n<li>错误代码: %1\$s<br>\n<li>错误信息: %s<br>\n".
"<li>发生时间: %s<br>\n</div>\n</div>\n</body>\n</html>";
echo sprintf($_Code, $this->code, $_SERVER['REQUEST_URI'], $this->file, $this->line, $this->message, date('Y-m-dH:i:s'));
return $this;
}
}
页: [1]
查看完整版本: php Exception