getTrace() as $frame) { $args = ""; if (isset($frame['args'])) { $args = array(); foreach ($frame['args'] as $arg) { if (is_string($arg)) { $args[] = "'" . $arg . "'"; } elseif (is_array($arg)) { $args[] = "Array"; } elseif (is_null($arg)) { $args[] = 'NULL'; } elseif (is_bool($arg)) { $args[] = ($arg) ? "true" : "false"; } elseif (is_object($arg)) { $args[] = get_class($arg); } elseif (is_resource($arg)) { $args[] = get_resource_type($arg); } else { $args[] = $arg; } } $args = join(", ", $args); } $rtn[] = sprintf( "#%s %s:%s %s(%s)", $count, isset($frame['file']) ? $frame['file'] : 'unknown file', isset($frame['line']) ? $frame['line'] : 'unknown line', (isset($frame['class'])) ? $frame['class'].$frame['type'].$frame['function'] : $frame['function'], $args ); $count++; } return $rtn; } function logError(string $err, string $errstr, array $trace){ $fdb = FileDB::db(ROOT.'/d_log/err_log.sqlite3', ROOT.'/f_install/sql/err_log.sql'); $date = date("Ymd_His"); $trace = array_map(function(string $text){ return str_replace(ROOT, '{ROOT}', $text); }, $trace); $fdb->insert('err_log', [ 'date'=>$date, 'err'=>$err, 'errstr'=>$errstr, 'trace'=>Json::encode($trace) ]); } 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 // through to the standard PHP error handler return false; } $e = new \Exception(); logError( getFriendlyErrorType($errno), $errstr, getExceptionTraceAsString($e) ); } set_error_handler("\sammo\logErrorByCustomHandler"); function logExceptionByCustomHandler(\Throwable $e){ logError( get_class($e), $e->getMessage(), getExceptionTraceAsString($e) ); echo $e->getTraceAsString(); throw $e; } set_exception_handler('\\sammo\\logExceptionByCustomHandler');