에러 표기 방식 변경.
- DB 에러도 throw exception을 수행 - exception handler 추가. - error 발생시 콜 스택을 json 형태로 보관
This commit is contained in:
+27
-3
@@ -7,6 +7,7 @@ mb_internal_encoding("UTF-8");
|
|||||||
mb_http_output('UTF-8');
|
mb_http_output('UTF-8');
|
||||||
mb_regex_encoding('UTF-8');
|
mb_regex_encoding('UTF-8');
|
||||||
|
|
||||||
|
|
||||||
function logErrorByCustomHandler(int $errno, string $errstr, string $errfile, int $errline, array $errcontext){
|
function logErrorByCustomHandler(int $errno, string $errstr, string $errfile, int $errline, array $errcontext){
|
||||||
if (!(error_reporting() & $errno)) {
|
if (!(error_reporting() & $errno)) {
|
||||||
// This error code is not included in error_reporting, so let it fall
|
// This error code is not included in error_reporting, so let it fall
|
||||||
@@ -15,10 +16,33 @@ function logErrorByCustomHandler(int $errno, string $errstr, string $errfile, in
|
|||||||
}
|
}
|
||||||
|
|
||||||
$date = date("Ymd_His");
|
$date = date("Ymd_His");
|
||||||
|
$e = new \Exception();
|
||||||
|
|
||||||
file_put_contents(ROOT.'/d_log/err_log.txt',"$date, $errno, $errstr, $errfile, $errline\n", FILE_APPEND);
|
$data = Json::encode([
|
||||||
|
'date'=>$date,
|
||||||
|
'errno'=>$errno,
|
||||||
|
'errstr'=>$errstr,
|
||||||
|
'aux'=>'error',
|
||||||
|
'trace'=>$e->getTraceAsString()
|
||||||
|
], Json::PRETTY);
|
||||||
|
|
||||||
/* Don't execute PHP internal error handler */
|
file_put_contents(ROOT.'/d_log/err_log.txt',"$data\n", FILE_APPEND);
|
||||||
//return true;
|
|
||||||
}
|
}
|
||||||
set_error_handler("\sammo\logErrorByCustomHandler");
|
set_error_handler("\sammo\logErrorByCustomHandler");
|
||||||
|
|
||||||
|
|
||||||
|
function logExceptionByCustomHandler(\Throwable $e){
|
||||||
|
|
||||||
|
$date = date("Ymd_His");
|
||||||
|
|
||||||
|
$data = Json::encode([
|
||||||
|
'date'=>$date,
|
||||||
|
'errno'=>$e->getCode(),
|
||||||
|
'errstr'=>$e->getMessage(),
|
||||||
|
'aux'=>'exception',
|
||||||
|
'trace'=>$e->getTraceAsString()
|
||||||
|
], Json::PRETTY);
|
||||||
|
|
||||||
|
file_put_contents(ROOT.'/d_log/err_log.txt',"$data\n", FILE_APPEND);
|
||||||
|
}
|
||||||
|
set_exception_handler('\\sammo\\logExceptionByCustomHandler');
|
||||||
@@ -29,6 +29,8 @@ class RootDB
|
|||||||
if (self::$uDB === null) {
|
if (self::$uDB === null) {
|
||||||
self::$uDB = new \MeekroDB(self::$host, self::$user, self::$password, self::$dbName, self::$port, self::$encoding);
|
self::$uDB = new \MeekroDB(self::$host, self::$user, self::$password, self::$dbName, self::$port, self::$encoding);
|
||||||
self::$uDB->connect_options[MYSQLI_OPT_INT_AND_FLOAT_NATIVE] = true;
|
self::$uDB->connect_options[MYSQLI_OPT_INT_AND_FLOAT_NATIVE] = true;
|
||||||
|
self::$uDB->throw_exception_on_error = true;
|
||||||
|
self::$uDB->throw_exception_on_nonsql_error = true;
|
||||||
}
|
}
|
||||||
return self::$uDB;
|
return self::$uDB;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ class DB{
|
|||||||
if(self::$uDB === null){
|
if(self::$uDB === null){
|
||||||
self::$uDB = new \MeekroDB(self::$host,self::$user,self::$password,self::$dbName,self::$port,self::$encoding);
|
self::$uDB = new \MeekroDB(self::$host,self::$user,self::$password,self::$dbName,self::$port,self::$encoding);
|
||||||
self::$uDB->connect_options[MYSQLI_OPT_INT_AND_FLOAT_NATIVE] = true;
|
self::$uDB->connect_options[MYSQLI_OPT_INT_AND_FLOAT_NATIVE] = true;
|
||||||
|
self::$uDB->throw_exception_on_error = true;
|
||||||
|
self::$uDB->throw_exception_on_nonsql_error = true;
|
||||||
}
|
}
|
||||||
return self::$uDB;
|
return self::$uDB;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user