From 4d2b10b9794606d25fdddf6f3c5983617b0f0fa3 Mon Sep 17 00:00:00 2001 From: hide_d Date: Thu, 12 Apr 2018 21:24:28 +0900 Subject: [PATCH] =?UTF-8?q?=EC=97=90=EB=9F=AC=20=ED=91=9C=EA=B8=B0=20?= =?UTF-8?q?=EB=B0=A9=EC=8B=9D=20=EB=B3=80=EA=B2=BD.=20-=20DB=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=EB=8F=84=20throw=20exception=EC=9D=84=20=EC=88=98?= =?UTF-8?q?=ED=96=89=20-=20exception=20handler=20=EC=B6=94=EA=B0=80.=20-?= =?UTF-8?q?=20error=20=EB=B0=9C=EC=83=9D=EC=8B=9C=20=EC=BD=9C=20=EC=8A=A4?= =?UTF-8?q?=ED=83=9D=EC=9D=84=20json=20=ED=98=95=ED=83=9C=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=B4=EA=B4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- f_config/config.php | 32 +++++++++++++++++++++++++---- f_install/templates/RootDB.orig.php | 2 ++ hwe/d_setting/DB.orig.php | 2 ++ 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/f_config/config.php b/f_config/config.php index 82eda0ed..de27bb6f 100644 --- a/f_config/config.php +++ b/f_config/config.php @@ -7,6 +7,7 @@ mb_internal_encoding("UTF-8"); mb_http_output('UTF-8'); mb_regex_encoding('UTF-8'); + function logErrorByCustomHandler(int $errno, string $errstr, string $errfile, int $errline, array $errcontext){ if (!(error_reporting() & $errno)) { // 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"); + $e = new \Exception(); - file_put_contents(ROOT.'/d_log/err_log.txt',"$date, $errno, $errstr, $errfile, $errline\n", FILE_APPEND); - - /* Don't execute PHP internal error handler */ - //return true; + $data = Json::encode([ + 'date'=>$date, + 'errno'=>$errno, + 'errstr'=>$errstr, + 'aux'=>'error', + 'trace'=>$e->getTraceAsString() + ], Json::PRETTY); + + file_put_contents(ROOT.'/d_log/err_log.txt',"$data\n", FILE_APPEND); } 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'); \ No newline at end of file diff --git a/f_install/templates/RootDB.orig.php b/f_install/templates/RootDB.orig.php index 632dc48c..c59ce260 100644 --- a/f_install/templates/RootDB.orig.php +++ b/f_install/templates/RootDB.orig.php @@ -29,6 +29,8 @@ class RootDB if (self::$uDB === null) { 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->throw_exception_on_error = true; + self::$uDB->throw_exception_on_nonsql_error = true; } return self::$uDB; } diff --git a/hwe/d_setting/DB.orig.php b/hwe/d_setting/DB.orig.php index 5ebb9046..71e7fdb3 100644 --- a/hwe/d_setting/DB.orig.php +++ b/hwe/d_setting/DB.orig.php @@ -27,6 +27,8 @@ class DB{ if(self::$uDB === null){ 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->throw_exception_on_error = true; + self::$uDB->throw_exception_on_nonsql_error = true; } return self::$uDB; }