From 3536d5c4137228f7a5ef2e953fbcc6d2bfe963f1 Mon Sep 17 00:00:00 2001 From: hide_d Date: Sun, 21 Apr 2019 22:15:41 +0900 Subject: [PATCH] =?UTF-8?q?err=5Flog=20=EA=B0=95=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- f_config/config.php | 16 ++++++++++++++-- f_install/sql/err_log.sql | 4 +++- hwe/lib.php | 2 +- showErrorLog.php | 8 +++++++- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/f_config/config.php b/f_config/config.php index f86fc6be..1123e653 100644 --- a/f_config/config.php +++ b/f_config/config.php @@ -88,19 +88,28 @@ function getExceptionTraceAsString($exception) { return $rtn; } -function logError(string $err, string $errstr, array $trace){ +function logError(string $err, string $errstr, string $errpath, array $trace){ $fdb = FileDB::db(ROOT.'/d_log/err_log.sqlite3', ROOT.'/f_install/sql/err_log.sql'); $date = date("Ymd_His"); + $errpath = str_replace(ROOT, '{ROOT}', $errpath); $trace = array_map(function(string $text){ return str_replace(ROOT, '{ROOT}', $text); }, $trace); + $owner = Util::get_client_ip(); + $session = Session::getInstance(); + if($session->isLoggedIn(true)){ + $owner .= '('.$session->getUserID().','.$session->userName.')'; + } + $fdb->insert('err_log', [ 'date'=>$date, 'err'=>$err, 'errstr'=>$errstr, - 'trace'=>Json::encode($trace) + 'errpath'=>$errpath, + 'trace'=>Json::encode($trace), + 'webuser'=>$owner ]); } @@ -116,6 +125,7 @@ function logErrorByCustomHandler(int $errno, string $errstr, string $errfile, in logError( getFriendlyErrorType($errno), $errstr, + $errfile.':'.$errline, getExceptionTraceAsString($e) ); } @@ -123,9 +133,11 @@ set_error_handler("\sammo\logErrorByCustomHandler"); function logExceptionByCustomHandler(\Throwable $e){ + logError( get_class($e), $e->getMessage(), + $e->getFile().':'.$e->getLine(), getExceptionTraceAsString($e) ); diff --git a/f_install/sql/err_log.sql b/f_install/sql/err_log.sql index c12c2f89..69e7fc29 100644 --- a/f_install/sql/err_log.sql +++ b/f_install/sql/err_log.sql @@ -3,7 +3,9 @@ CREATE TABLE IF NOT EXISTS `err_log` ( `date` TEXT NOT NULL, `err` TEXT NOT NULL, `errstr` TEXT NOT NULL, - `trace` TEXT NOT NULL + `errpath` TEXT NOT NULL, + `trace` TEXT NOT NULL, + `webuser` TEXT NULL ); CREATE INDEX IF NOT EXISTS `date` ON `err_log` ( `date` DESC diff --git a/hwe/lib.php b/hwe/lib.php index 70f0c028..47a357ac 100644 --- a/hwe/lib.php +++ b/hwe/lib.php @@ -34,7 +34,7 @@ function Error($message='', $url="") $url = $_SERVER['REQUEST_URI']; } $e = new \Exception(); - logError("aux_err", $message, getExceptionTraceAsString($e)); + logError("aux_err", $message, '', getExceptionTraceAsString($e)); $templates = new \League\Plates\Engine(__dir__.'/templates'); diff --git a/showErrorLog.php b/showErrorLog.php index 0b0fc974..320af10a 100644 --- a/showErrorLog.php +++ b/showErrorLog.php @@ -29,7 +29,9 @@ $err_logs = $fdb->select('err_log', [ 'date', 'err', 'errstr', - 'trace' + 'errpath', + 'trace', + 'webuser' ], [ 'ORDER'=>['id'=>'DESC'], 'LIMIT'=>100 @@ -61,9 +63,13 @@ $err_logs = $fdb->select('err_log', [