diff --git a/Annotation/Loader.php b/Annotation/Loader.php index 5910f60d..c090f019 100644 --- a/Annotation/Loader.php +++ b/Annotation/Loader.php @@ -198,9 +198,7 @@ class Loader extends BaseObject $this->_classes[$replace->getName()] = $_array; } catch (Throwable $throwable) { - $this->error($throwable->getMessage()); - $this->error($throwable->getFile()); - $this->error($throwable->getLine()); + $this->addError($throwable, 'throwable'); } } } diff --git a/Database/Pagination.php b/Database/Pagination.php index 9b885677..e37d5bb6 100644 --- a/Database/Pagination.php +++ b/Database/Pagination.php @@ -198,7 +198,7 @@ class Pagination extends Component try { call_user_func($callback, $data, $param); } catch (\Throwable $exception) { - $this->addError($exception); + $this->addError($exception, 'throwable'); } finally { $event = Snowflake::app()->getEvent(); $event->trigger(Event::SYSTEM_RESOURCE_RELEASES); diff --git a/Gii/GiiController.php b/Gii/GiiController.php index b86bce7a..89a34ff7 100644 --- a/Gii/GiiController.php +++ b/Gii/GiiController.php @@ -55,7 +55,7 @@ namespace {$namespace}; $import = $this->getImports($path['path'] . '/' . $managerName . 'Controller.php', $class); } catch (\Throwable $Exception) { - exit(logger()->addError($Exception)); + exit(logger()->addError($Exception, 'throwable')); } } else { $import = "use Snowflake; diff --git a/Gii/GiiInterceptor.php b/Gii/GiiInterceptor.php index 4c89d6b3..5d6005a3 100644 --- a/Gii/GiiInterceptor.php +++ b/Gii/GiiInterceptor.php @@ -42,7 +42,7 @@ namespace App\Http\Interceptor; $html .= $this->getImports($file, $class); } catch (\Throwable $exception) { - return logger()->addError($exception); + return logger()->addError($exception, 'throwable'); } } else { $html .= ' diff --git a/Gii/GiiModel.php b/Gii/GiiModel.php index 9278c24d..f55c4eb0 100644 --- a/Gii/GiiModel.php +++ b/Gii/GiiModel.php @@ -68,7 +68,7 @@ namespace ' . $namespace . '; $html .= $imports . PHP_EOL; } } catch (\Throwable $e) { - logger()->error($e->getMessage()); + logger()->addError($e,'throwable'); } } diff --git a/HttpServer/Abstracts/Callback.php b/HttpServer/Abstracts/Callback.php index add4c69f..533d625f 100644 --- a/HttpServer/Abstracts/Callback.php +++ b/HttpServer/Abstracts/Callback.php @@ -42,7 +42,7 @@ abstract class Callback extends HttpService $this->eventNotify($message); } catch (\Throwable $exception) { - $this->addError($exception); + $this->addError($exception,'throwable'); } } diff --git a/HttpServer/Client/Client.php b/HttpServer/Client/Client.php index b518404c..04ef31f8 100644 --- a/HttpServer/Client/Client.php +++ b/HttpServer/Client/Client.php @@ -66,6 +66,7 @@ class Client extends ClientAbstracts } return $this->fail($client->getStatusCode(), $message, $body, $client->getHeaders()); } catch (\Throwable $exception) { + $this->addError($exception,'rpc'); return $this->fail(500, $exception->getMessage(), [ 'file' => $exception->getFile(), 'line' => $exception->getLine() diff --git a/HttpServer/Events/OnClose.php b/HttpServer/Events/OnClose.php index 9c8e7db4..0366398f 100644 --- a/HttpServer/Events/OnClose.php +++ b/HttpServer/Events/OnClose.php @@ -35,7 +35,7 @@ class OnClose extends Callback try { $this->execute($server, $fd); } catch (\Throwable $exception) { - $this->addError($exception); + $this->addError($exception,'throwable'); } finally { fire(Event::SYSTEM_RESOURCE_RELEASES); logger()->insert(); diff --git a/HttpServer/Events/OnHandshake.php b/HttpServer/Events/OnHandshake.php index 32d3ad3a..d9cd976c 100644 --- a/HttpServer/Events/OnHandshake.php +++ b/HttpServer/Events/OnHandshake.php @@ -97,7 +97,7 @@ class OnHandshake extends Callback $eventName = 'listen ' . $clientInfo['server_port'] . ' ' . Event::SERVER_HANDSHAKE; $event->trigger($eventName, [$request, $response]); } catch (\Throwable $exception) { - $this->addError($exception); + $this->addError($exception,'throwable'); $this->disconnect($response, 500); } finally { fire(Event::SYSTEM_RESOURCE_CLEAN); diff --git a/HttpServer/Events/OnRequest.php b/HttpServer/Events/OnRequest.php index 76a8a844..9a202300 100644 --- a/HttpServer/Events/OnRequest.php +++ b/HttpServer/Events/OnRequest.php @@ -65,6 +65,7 @@ class OnRequest extends Callback return $result; } catch (ExitException | Error | \Throwable $exception) { + $this->addError($exception, 'throwable'); return $this->sendErrorMessage($request, $response, $exception); } finally { $this->event->trigger(Event::SYSTEM_RESOURCE_RELEASES); diff --git a/HttpServer/Events/OnTask.php b/HttpServer/Events/OnTask.php index 47311bcd..1b14704e 100644 --- a/HttpServer/Events/OnTask.php +++ b/HttpServer/Events/OnTask.php @@ -118,7 +118,7 @@ class OnTask extends Callback } catch (\Throwable $exception) { $finish['status'] = 'error'; $finish['info'] = $this->format($exception); - $this->error($exception, 'Task'); + $this->addError($exception, 'Task'); return $finish; } finally { diff --git a/HttpServer/Events/OnWorkerStart.php b/HttpServer/Events/OnWorkerStart.php index 11f1eb39..b7502e12 100644 --- a/HttpServer/Events/OnWorkerStart.php +++ b/HttpServer/Events/OnWorkerStart.php @@ -73,7 +73,7 @@ class OnWorkerStart extends Callback try { fire(Event::SERVER_WORKER_START, [$worker_id]); } catch (\Throwable $exception) { - $this->addError($exception); + $this->addError($exception,'throwable'); write($exception->getMessage(), 'worker'); } } diff --git a/HttpServer/Route/Node.php b/HttpServer/Route/Node.php index 6cc08606..3fe79bfe 100644 --- a/HttpServer/Route/Node.php +++ b/HttpServer/Route/Node.php @@ -287,7 +287,7 @@ class Node extends HttpService return [$reflect->newInstance(), $action]; } catch (Throwable $exception) { $this->_error = $exception->getMessage(); - $this->error($exception, 'router'); + $this->addError($exception, 'router'); return null; } } @@ -592,7 +592,7 @@ class Node extends HttpService } return $this->runWith(...func_get_args()); } catch (Throwable $throwable) { - $this->error($throwable->getMessage()); + $this->addError($throwable->getMessage(),'throwable'); return Json::to(401, $throwable->getMessage()); } } diff --git a/HttpServer/Route/Reduce.php b/HttpServer/Route/Reduce.php index c0ec81e9..b8b81452 100644 --- a/HttpServer/Route/Reduce.php +++ b/HttpServer/Route/Reduce.php @@ -38,6 +38,7 @@ class Reduce } return $pipe->onHandler($request, $passable); } catch (\Throwable $throwable) { + logger()->addError($throwable, 'throwable'); return Json::to(0, $throwable); } }; diff --git a/HttpServer/Route/Router.php b/HttpServer/Route/Router.php index 46a901ac..30f8201d 100644 --- a/HttpServer/Route/Router.php +++ b/HttpServer/Route/Router.php @@ -515,7 +515,7 @@ class Router extends HttpService implements RouterInterface } return $node->afterDispatch($response); } catch (\Throwable $exception) { - $this->addError($exception); + $this->addError($exception,'throwable'); $Code = $exception->getCode() == 0 ? 500 : $exception->getCode(); @@ -659,7 +659,7 @@ class Router extends HttpService implements RouterInterface $router = $this; include_once "{$files}"; } catch (\Throwable $exception) { - $this->error($exception); + $this->addError($exception,'throwable'); } finally { if (isset($exception)) { unset($exception); diff --git a/HttpServer/Server.php b/HttpServer/Server.php index 7917ec66..f2fa26e3 100644 --- a/HttpServer/Server.php +++ b/HttpServer/Server.php @@ -520,7 +520,7 @@ class Server extends HttpService $annotation->instanceDirectoryFiles(RPC_SERVICE_PATH); $annotation->instanceDirectoryFiles(RPC_CLIENT_PATH); } catch (\Throwable $exception) { - $this->addError($exception); + $this->addError($exception,'throwable'); } }); } diff --git a/Kafka/Kafka.php b/Kafka/Kafka.php index 68e2de8d..ba2d2666 100644 --- a/Kafka/Kafka.php +++ b/Kafka/Kafka.php @@ -58,7 +58,7 @@ class Kafka extends \Snowflake\Process\Process $this->resolve($topic, $conf['interval'] ?? 1000); } while (true); } catch (Throwable $exception) { - $this->application->error($exception); + logger()->addError($exception,'throwable'); } } @@ -85,7 +85,7 @@ class Kafka extends \Snowflake\Process\Process $this->application->error($message->errstr()); } } catch (Throwable $exception) { - $this->application->error($exception); + logger()->addError($exception,'throwable'); } } @@ -111,7 +111,7 @@ class Kafka extends \Snowflake\Process\Process } $class->onHandler(Snowflake::createObject(Struct::class, [$topic, $message])); } catch (Throwable $exception) { - $this->application->error($exception); + logger()->addError($exception,'throwable'); } }); } @@ -148,7 +148,7 @@ class Kafka extends \Snowflake\Process\Process return [$conf, $topicConf, $kafka]; } catch (Throwable $exception) { - $this->application->error($exception); + logger()->addError($exception,'throwable'); return [null, null, null]; } diff --git a/System/Crontab/Consumer.php b/System/Crontab/Consumer.php index 8f1d905f..31262b12 100644 --- a/System/Crontab/Consumer.php +++ b/System/Crontab/Consumer.php @@ -59,7 +59,7 @@ class Consumer extends Process Consumer::addTask($crontab); } } catch (\Throwable $throwable) { - $this->application->addError($throwable->getMessage()); + logger()->addError($throwable->getMessage(),'throwable'); } finally { fire(Event::SYSTEM_RESOURCE_RELEASES); } diff --git a/System/Event.php b/System/Event.php index fa4ea710..8ea64d25 100644 --- a/System/Event.php +++ b/System/Event.php @@ -232,7 +232,7 @@ class Event extends BaseObject } return true; } catch (\Throwable $throwable) { - return $this->addError($throwable); + return $this->addError($throwable,'throwable'); } } diff --git a/System/Process/ServerInotify.php b/System/Process/ServerInotify.php index e439f6c5..6d016020 100644 --- a/System/Process/ServerInotify.php +++ b/System/Process/ServerInotify.php @@ -232,7 +232,7 @@ class ServerInotify extends Process } /** - * 清理所有inotify监听 + * @throws Exception */ public function clearWatch() { @@ -240,6 +240,7 @@ class ServerInotify extends Process try { inotify_rm_watch($this->inotify, $wd); } catch (\Throwable $exception) { + logger()->addError($exception, 'throwable'); } } $this->watchFiles = []; diff --git a/function.php b/function.php index faeb412a..2cdb06ae 100644 --- a/function.php +++ b/function.php @@ -15,6 +15,7 @@ use HttpServer\Service\Receive; use HttpServer\Service\Websocket; use JetBrains\PhpStorm\Pure; use Snowflake\Abstracts\Config; +use Snowflake\Application; use Snowflake\Error\Logger; use Snowflake\Exception\ComponentException; use Snowflake\Exception\ConfigException; @@ -319,6 +320,19 @@ if (!function_exists('aop')) { } +if (!function_exists('app')) { + + + /** + * @return Application|null + */ + #[Pure] function app(): ?Application + { + return Snowflake::app(); + } + +} + if (!function_exists('instance_load')) { function instance_load()