Skip to content

Commit a692e32

Browse files
author
liu21st@gmail.com
committed
增加致命错误捕获机制
记录SQL错误日志 git-svn-id: http://thinkphp.googlecode.com/svn/trunk@2965 539fd3ec-2725-0410-b7ab-251e373a8e33
1 parent db58b30 commit a692e32

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

ThinkPHP/Lib/Core/Think.class.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class Think {
3636
*/
3737
static public function start() {
3838
// 设定错误和异常处理
39+
register_shutdown_function(array('Think','fatalError'));
3940
set_error_handler(array('Think','appError'));
4041
set_exception_handler(array('Think','appException'));
4142
// 注册AUTOLOAD方法
@@ -261,8 +262,8 @@ static public function appError($errno, $errstr, $errfile, $errline) {
261262
switch ($errno) {
262263
case E_ERROR:
263264
case E_USER_ERROR:
264-
$errorStr = "[$errno] $errstr ".basename($errfile)."$errline 行.";
265-
if(C('LOG_RECORD')) Log::write($errorStr,Log::ERR);
265+
$errorStr = "$errstr ".basename($errfile)."$errline 行.";
266+
if(C('LOG_RECORD')) Log::write("[$errno] ".$errorStr,Log::ERR);
266267
halt($errorStr);
267268
break;
268269
case E_STRICT:
@@ -274,6 +275,16 @@ static public function appError($errno, $errstr, $errfile, $errline) {
274275
break;
275276
}
276277
}
278+
279+
// 捕捉致命错误
280+
static public function fatalError() {
281+
ob_clean();
282+
if ($e = error_get_last()) {
283+
if ($e['type']>0) {
284+
Think::appError($e['type'],$e['message'],$e['file'],$e['line']);
285+
}
286+
}
287+
}
277288

278289
/**
279290
+----------------------------------------------------------

ThinkPHP/Lib/Driver/Db/DbMysql.class.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ public function error() {
389389
if($this->debug && '' != $this->queryStr){
390390
$this->error .= "\n [ SQL语句 ] : ".$this->queryStr;
391391
}
392+
Log::record($this->error,Log::ERR);
392393
return $this->error;
393394
}
394395

ThinkPHP/Lib/Driver/Db/DbMysqli.class.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ public function error() {
383383
if($this->debug && '' != $this->queryStr){
384384
$this->error .= "\n [ SQL语句 ] : ".$this->queryStr;
385385
}
386+
Log::record($this->error,Log::ERR);
386387
return $this->error;
387388
}
388389

0 commit comments

Comments
 (0)