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 5ba3a90d..47a357ac 100644 --- a/hwe/lib.php +++ b/hwe/lib.php @@ -33,7 +33,8 @@ function Error($message='', $url="") if (!$url) { $url = $_SERVER['REQUEST_URI']; } - file_put_contents(__dir__."/logs/".UniqueConst::$serverID."/_db_bug.txt", "{\"url\":\"$url\",\"msg\":\"$message\"}\n", FILE_APPEND); + $e = new \Exception(); + 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', [