mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-22 08:05:34 +08:00
replace console with logger
This commit is contained in:
@@ -10,11 +10,8 @@ use Doctrine\Common\Annotations\AnnotationException;
|
||||
use Error;
|
||||
use Exception;
|
||||
use Throwable;
|
||||
use ZM\Adapters\OneBot11Adapter;
|
||||
use ZM\Config\ZMConfig;
|
||||
use ZM\Console\Console;
|
||||
use ZM\Exception\InterruptException;
|
||||
use ZM\Module\QQBot;
|
||||
use ZM\Store\LightCacheInside;
|
||||
use ZM\Store\Lock\SpinLock;
|
||||
use ZM\Store\ZMAtomic;
|
||||
@@ -62,7 +59,7 @@ class EventDispatcher
|
||||
$this->log = true;
|
||||
}
|
||||
if ($this->log) {
|
||||
Console::verbose("[事件分发{$this->eid}] 开始分发事件: " . $class);
|
||||
logger()->debug("[事件分发{$this->eid}] 开始分发事件: " . $class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +93,7 @@ class EventDispatcher
|
||||
public function setRuleFunction(callable $rule = null): EventDispatcher
|
||||
{
|
||||
if ($this->log) {
|
||||
Console::verbose("[事件分发{$this->eid}] 设置事件rule: " . $this->class);
|
||||
logger()->debug("[事件分发{$this->eid}] 设置事件rule: " . $this->class);
|
||||
}
|
||||
$this->rule = $rule;
|
||||
return $this;
|
||||
@@ -105,7 +102,7 @@ class EventDispatcher
|
||||
public function setReturnFunction(callable $return_func): EventDispatcher
|
||||
{
|
||||
if ($this->log) {
|
||||
Console::verbose("[事件分发{$this->eid}] 设置事件returnFunc: " . $this->class);
|
||||
logger()->debug("[事件分发{$this->eid}] 设置事件returnFunc: " . $this->class);
|
||||
}
|
||||
$this->return_func = $return_func;
|
||||
return $this;
|
||||
@@ -126,14 +123,14 @@ class EventDispatcher
|
||||
// }
|
||||
$this->dispatchEvent($v, $this->rule, ...$params);
|
||||
if ($this->log) {
|
||||
Console::verbose("[事件分发{$this->eid}] 单一对象 " . $v->class . '::' . (is_string($v->method) ? $v->method : '{closure}') . ' 分发结束。');
|
||||
logger()->debug("[事件分发{$this->eid}] 单一对象 " . $v->class . '::' . (is_string($v->method) ? $v->method : '{closure}') . ' 分发结束。');
|
||||
}
|
||||
if ($this->status == self::STATUS_BEFORE_FAILED || $this->status == self::STATUS_RULE_FAILED) {
|
||||
continue;
|
||||
}
|
||||
if (is_callable($this->return_func) && $this->status === self::STATUS_NORMAL) {
|
||||
if ($this->log) {
|
||||
Console::verbose("[事件分发{$this->eid}] 单一对象 " . $v->class . '::' . $v->method . ' 正在执行返回值处理函数 ...');
|
||||
logger()->debug("[事件分发{$this->eid}] 单一对象 " . $v->class . '::' . $v->method . ' 正在执行返回值处理函数 ...');
|
||||
}
|
||||
($this->return_func)($this->store);
|
||||
}
|
||||
@@ -167,11 +164,11 @@ class EventDispatcher
|
||||
$q_f = $v->method;
|
||||
if (($q_c ?? '') === '' && ($q_f instanceof Closure)) {
|
||||
if ($this->log) {
|
||||
Console::verbose("[事件分发{$this->eid}] 闭包函数的事件触发过程!");
|
||||
logger()->debug("[事件分发{$this->eid}] 闭包函数的事件触发过程!");
|
||||
}
|
||||
if ($rule_func !== null && !$rule_func($v)) {
|
||||
if ($this->log) {
|
||||
Console::verbose("[事件分发{$this->eid}] 闭包函数下的 ruleFunc 判断为 false, 拒绝执行此方法。");
|
||||
logger()->debug("[事件分发{$this->eid}] 闭包函数下的 ruleFunc 判断为 false, 拒绝执行此方法。");
|
||||
}
|
||||
$this->status = self::STATUS_RULE_FAILED;
|
||||
return false;
|
||||
@@ -181,22 +178,22 @@ class EventDispatcher
|
||||
return true;
|
||||
}
|
||||
if ($this->log) {
|
||||
Console::verbose("[事件分发{$this->eid}] 正在判断 " . $q_c . '::' . $q_f . ' 方法下的 ruleFunc ...');
|
||||
logger()->debug("[事件分发{$this->eid}] 正在判断 " . $q_c . '::' . $q_f . ' 方法下的 ruleFunc ...');
|
||||
}
|
||||
if ($rule_func !== null && !$rule_func($v)) {
|
||||
if ($this->log) {
|
||||
Console::verbose("[事件分发{$this->eid}] " . $q_c . '::' . $q_f . ' 方法下的 ruleFunc 判断为 false, 拒绝执行此方法。');
|
||||
logger()->debug("[事件分发{$this->eid}] " . $q_c . '::' . $q_f . ' 方法下的 ruleFunc 判断为 false, 拒绝执行此方法。');
|
||||
}
|
||||
$this->status = self::STATUS_RULE_FAILED;
|
||||
return false;
|
||||
}
|
||||
if ($this->log) {
|
||||
Console::verbose("[事件分发{$this->eid}] " . $q_c . '::' . $q_f . ' 方法下的 ruleFunc 为真,继续执行方法本身 ...');
|
||||
logger()->debug("[事件分发{$this->eid}] " . $q_c . '::' . $q_f . ' 方法下的 ruleFunc 为真,继续执行方法本身 ...');
|
||||
}
|
||||
if (isset(EventManager::$middleware_map[$q_c][$q_f])) {
|
||||
$middlewares = EventManager::$middleware_map[$q_c][$q_f];
|
||||
if ($this->log) {
|
||||
Console::verbose("[事件分发{$this->eid}] " . $q_c . '::' . $q_f . ' 方法还绑定了 Middleware:' . implode(', ', array_map(function ($x) {
|
||||
logger()->debug("[事件分发{$this->eid}] " . $q_c . '::' . $q_f . ' 方法还绑定了 Middleware:' . implode(', ', array_map(function ($x) {
|
||||
return $x->middleware;
|
||||
}, $middlewares)));
|
||||
}
|
||||
@@ -219,18 +216,18 @@ class EventDispatcher
|
||||
$r[$k]->current_event = $v;
|
||||
if (isset($middleware_obj['before'])) {
|
||||
if ($this->log) {
|
||||
Console::verbose("[事件分发{$this->eid}] Middleware 存在前置事件,执行中 ...");
|
||||
logger()->debug("[事件分发{$this->eid}] Middleware 存在前置事件,执行中 ...");
|
||||
}
|
||||
$rs = $middleware_obj['before'];
|
||||
$before_result = $r[$k]->{$rs}(...$params);
|
||||
if ($before_result === false) {
|
||||
if ($this->log) {
|
||||
Console::verbose("[事件分发{$this->eid}] Middleware 前置事件为 false,停止执行原事件,开始执行下一事件。");
|
||||
logger()->debug("[事件分发{$this->eid}] Middleware 前置事件为 false,停止执行原事件,开始执行下一事件。");
|
||||
}
|
||||
break;
|
||||
}
|
||||
if ($this->log) {
|
||||
Console::verbose("[事件分发{$this->eid}] Middleware 前置事件为 true,继续执行原事件。");
|
||||
logger()->debug("[事件分发{$this->eid}] Middleware 前置事件为 true,继续执行原事件。");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -239,18 +236,18 @@ class EventDispatcher
|
||||
$q_o = ZMUtil::getModInstance($q_c);
|
||||
$q_o->_running_annotation = $v;
|
||||
if ($this->log) {
|
||||
Console::verbose("[事件分发{$this->eid}] 正在执行方法 " . $q_c . '::' . $q_f . ' ...');
|
||||
logger()->debug("[事件分发{$this->eid}] 正在执行方法 " . $q_c . '::' . $q_f . ' ...');
|
||||
}
|
||||
$this->store = container()->call([$q_o, $q_f], $params);
|
||||
} catch (Exception $e) {
|
||||
if ($e instanceof InterruptException) {
|
||||
if ($this->log) {
|
||||
Console::verbose("[事件分发{$this->eid}] 检测到事件阻断调用,正在跳出事件分发器 ...");
|
||||
logger()->debug("[事件分发{$this->eid}] 检测到事件阻断调用,正在跳出事件分发器 ...");
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
if ($this->log) {
|
||||
Console::verbose("[事件分发{$this->eid}] 方法 " . $q_c . '::' . $q_f . ' 执行过程中抛出了异常,正在倒序查找 Middleware 中的捕获方法 ...');
|
||||
logger()->debug("[事件分发{$this->eid}] 方法 " . $q_c . '::' . $q_f . ' 执行过程中抛出了异常,正在倒序查找 Middleware 中的捕获方法 ...');
|
||||
}
|
||||
for ($i = count($middlewares) - 1; $i >= 0; --$i) {
|
||||
$middleware_obj = EventManager::$middlewares[$middlewares[$i]->middleware];
|
||||
@@ -260,7 +257,7 @@ class EventDispatcher
|
||||
foreach ($middleware_obj['exceptions'] as $name => $method) {
|
||||
if ($e instanceof $name) {
|
||||
if ($this->log) {
|
||||
Console::verbose("[事件分发{$this->eid}] 方法 " . $q_c . '::' . $q_f . ' 的异常 ' . get_class($e) . ' 被 Middleware:' . $middlewares[$i] . ' 下的 ' . get_class($r[$i]) . '::' . $method . ' 捕获。');
|
||||
logger()->debug("[事件分发{$this->eid}] 方法 " . $q_c . '::' . $q_f . ' 的异常 ' . get_class($e) . ' 被 Middleware:' . $middlewares[$i] . ' 下的 ' . get_class($r[$i]) . '::' . $method . ' 捕获。');
|
||||
}
|
||||
$r[$i]->{$method}($e);
|
||||
self::interrupt();
|
||||
@@ -274,11 +271,11 @@ class EventDispatcher
|
||||
$middleware_obj = EventManager::$middlewares[$middlewares[$i]->middleware];
|
||||
if (isset($middleware_obj['after'], $r[$i])) {
|
||||
if ($this->log) {
|
||||
Console::verbose("[事件分发{$this->eid}] Middleware 存在后置事件,执行中 ...");
|
||||
logger()->debug("[事件分发{$this->eid}] Middleware 存在后置事件,执行中 ...");
|
||||
}
|
||||
$r[$i]->{$middleware_obj['after']}(...$params);
|
||||
if ($this->log) {
|
||||
Console::verbose("[事件分发{$this->eid}] Middleware 后置事件执行完毕!");
|
||||
logger()->debug("[事件分发{$this->eid}] Middleware 后置事件执行完毕!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -291,7 +288,7 @@ class EventDispatcher
|
||||
$q_o = ZMUtil::getModInstance($q_c);
|
||||
$q_o->_running_annotation = $v;
|
||||
if ($this->log) {
|
||||
Console::verbose("[事件分发{$this->eid}] 正在执行方法 " . $q_c . '::' . $q_f . ' ...');
|
||||
logger()->debug("[事件分发{$this->eid}] 正在执行方法 " . $q_c . '::' . $q_f . ' ...');
|
||||
}
|
||||
$this->store = container()->call([$q_o, $q_f], $params);
|
||||
$this->status = self::STATUS_NORMAL;
|
||||
|
||||
@@ -32,9 +32,9 @@ class EventManager
|
||||
public static function addEvent($event_name, ?AnnotationBase $event_obj)
|
||||
{
|
||||
if ($event_obj->method instanceof Closure) {
|
||||
Console::debug("Adding event {$event_name} at @Anonymous");
|
||||
logger()->debug("Adding event {$event_name} at @Anonymous");
|
||||
} else {
|
||||
Console::debug("Adding event {$event_name} at " . ($event_obj->class) . ':' . ($event_obj->method));
|
||||
logger()->debug("Adding event {$event_name} at " . ($event_obj->class) . ':' . ($event_obj->method));
|
||||
self::$event_map[$event_obj->class][$event_obj->method][] = $event_obj;
|
||||
}
|
||||
self::$events[$event_name][] = $event_obj;
|
||||
@@ -66,7 +66,7 @@ class EventManager
|
||||
}
|
||||
// echo server()->worker_id.PHP_EOL;
|
||||
$plain_class = $vss->class;
|
||||
Console::debug('Added Middleware-based timer: ' . $plain_class . ' -> ' . $vss->method);
|
||||
logger()->debug('Added Middleware-based timer: ' . $plain_class . ' -> ' . $vss->method);
|
||||
Timer::tick($vss->tick_ms, function () use ($vss, $dispatcher) {
|
||||
set_coroutine_params([]);
|
||||
if (ZMAtomic::get('stop_signal')->get() != 0) {
|
||||
|
||||
@@ -28,26 +28,26 @@ class EventMapIterator implements Iterator
|
||||
#[ReturnTypeWillChange]
|
||||
public function current()
|
||||
{
|
||||
Console::debug('从 [' . $this->offset . '] 开始获取');
|
||||
logger()->debug('从 [' . $this->offset . '] 开始获取');
|
||||
return EventManager::$event_map[$this->class][$this->method][$this->offset];
|
||||
}
|
||||
|
||||
public function next(): void
|
||||
{
|
||||
Console::debug('下一个offset为 [' . ++$this->offset . ']');
|
||||
logger()->debug('下一个offset为 [' . ++$this->offset . ']');
|
||||
$this->nextToValid();
|
||||
}
|
||||
|
||||
#[ReturnTypeWillChange]
|
||||
public function key()
|
||||
{
|
||||
Console::debug('返回key:' . $this->offset);
|
||||
logger()->debug('返回key:' . $this->offset);
|
||||
return isset(EventManager::$event_map[$this->class][$this->method][$this->offset]) ? $this->offset : null;
|
||||
}
|
||||
|
||||
public function valid($s = false): bool
|
||||
{
|
||||
Console::debug(
|
||||
logger()->debug(
|
||||
"[{$this->offset}] " .
|
||||
($s ? 'valid' : '') . '存在:' .
|
||||
(!isset(EventManager::$event_map[$this->class][$this->method][$this->offset]) ? Console::setColor('false', 'red') : ('true' .
|
||||
@@ -60,7 +60,7 @@ class EventMapIterator implements Iterator
|
||||
|
||||
public function rewind(): void
|
||||
{
|
||||
Console::debug('回到0');
|
||||
logger()->debug('回到0');
|
||||
$this->offset = 0;
|
||||
$this->nextToValid();
|
||||
}
|
||||
@@ -73,6 +73,6 @@ class EventMapIterator implements Iterator
|
||||
) {
|
||||
++$this->offset;
|
||||
}
|
||||
Console::debug('内部偏移offset为 [' . $this->offset . ']');
|
||||
logger()->debug('内部偏移offset为 [' . $this->offset . ']');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ class OnBeforeReload implements SwooleEvent
|
||||
{
|
||||
public function onCall(Server $server)
|
||||
{
|
||||
Console::info(Console::setColor('Reloading server...', 'gold'));
|
||||
logger()->info(Console::setColor('Reloading server...', 'gold'));
|
||||
for ($i = 0; $i < ZM_WORKER_NUM; ++$i) {
|
||||
Process::kill(zm_atomic('_#worker_' . $i)->get(), SIGUSR1);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ class OnClose implements SwooleEvent
|
||||
public function onCall($server, $fd)
|
||||
{
|
||||
unset(Context::$context[Coroutine::getCid()]);
|
||||
Console::debug('Calling Swoole "close" event from fd=' . $fd);
|
||||
logger()->debug('Calling Swoole "close" event from fd=' . $fd);
|
||||
$conn = ManagerGM::get($fd);
|
||||
if ($conn === null) {
|
||||
return;
|
||||
|
||||
@@ -42,7 +42,7 @@ class OnManagerStart implements SwooleEvent
|
||||
|
||||
public function onCall(Server $server)
|
||||
{
|
||||
Console::debug('Calling onManagerStart event(1)');
|
||||
logger()->debug('Calling onManagerStart event(1)');
|
||||
if (!Framework::$argv['disable-safe-exit']) {
|
||||
SignalListener::signalManager();
|
||||
}
|
||||
@@ -54,17 +54,17 @@ class OnManagerStart implements SwooleEvent
|
||||
});
|
||||
if (Framework::$argv['watch']) {
|
||||
if (extension_loaded('inotify')) {
|
||||
Console::info('Enabled File watcher, framework will reload automatically.');
|
||||
logger()->info('Enabled File watcher, framework will reload automatically.');
|
||||
$fd = inotify_init();
|
||||
$this->addWatcher(DataProvider::getSourceRootDir() . '/src', $fd);
|
||||
Event::add($fd, function () use ($fd) {
|
||||
$r = inotify_read($fd);
|
||||
Console::verbose('File updated: ' . $r[0]['name']);
|
||||
logger()->debug('File updated: ' . $r[0]['name']);
|
||||
ZMUtil::reload();
|
||||
});
|
||||
Framework::$argv['polling-watch'] = false; // 如果开启了inotify则关闭轮询热更新
|
||||
} else {
|
||||
Console::warning(zm_internal_errcode('E00024') . '你还没有安装或启用 inotify 扩展,将默认使用轮询检测模式开启热更新!');
|
||||
logger()->warning(zm_internal_errcode('E00024') . '你还没有安装或启用 inotify 扩展,将默认使用轮询检测模式开启热更新!');
|
||||
Framework::$argv['polling-watch'] = true;
|
||||
}
|
||||
}
|
||||
@@ -84,7 +84,7 @@ class OnManagerStart implements SwooleEvent
|
||||
});
|
||||
}
|
||||
if (Framework::$argv['interact']) {
|
||||
Console::info('Interact mode');
|
||||
logger()->info('Interact mode');
|
||||
ZMBuf::$terminal = $r = STDIN;
|
||||
Event::add($r, function () use ($r) {
|
||||
$fget = fgets($r);
|
||||
@@ -116,7 +116,7 @@ class OnManagerStart implements SwooleEvent
|
||||
});
|
||||
$dispatcher->dispatchEvents($server);
|
||||
*/
|
||||
Console::verbose('进程 Manager 已启动');
|
||||
logger()->debug('进程 Manager 已启动');
|
||||
}
|
||||
|
||||
private function addWatcher($maindir, $fd)
|
||||
@@ -127,7 +127,7 @@ class OnManagerStart implements SwooleEvent
|
||||
}
|
||||
foreach ($dir as $subdir) {
|
||||
if (is_dir($maindir . '/' . $subdir)) {
|
||||
Console::debug('添加监听目录:' . $maindir . '/' . $subdir);
|
||||
logger()->debug('添加监听目录:' . $maindir . '/' . $subdir);
|
||||
inotify_add_watch($fd, $maindir . '/' . $subdir, IN_ATTRIB | IN_ISDIR);
|
||||
$this->addWatcher($maindir . '/' . $subdir, $fd);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ namespace ZM\Event\SwooleEvent;
|
||||
|
||||
use Swoole\Process;
|
||||
use ZM\Annotation\Swoole\SwooleHandler;
|
||||
use ZM\Console\Console;
|
||||
use ZM\Event\SwooleEvent;
|
||||
use ZM\Utils\Manager\ProcessManager;
|
||||
|
||||
@@ -23,7 +22,7 @@ class OnManagerStop implements SwooleEvent
|
||||
Process::kill($v->pid, SIGTERM);
|
||||
}
|
||||
}
|
||||
Console::verbose('进程 Manager 已停止!');
|
||||
logger()->debug('进程 Manager 已停止!');
|
||||
ProcessManager::removeProcessState(ZM_PROCESS_MANAGER);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class OnMessage implements SwooleEvent
|
||||
{
|
||||
public function onCall($server, Frame $frame)
|
||||
{
|
||||
Console::debug('Calling Swoole "message" from fd=' . $frame->fd . ': ' . TermColor::ITALIC . $frame->data . TermColor::RESET);
|
||||
logger()->debug('Calling Swoole "message" from fd=' . $frame->fd . ': ' . TermColor::ITALIC . $frame->data . TermColor::RESET);
|
||||
unset(Context::$context[Coroutine::getCid()]);
|
||||
$conn = ManagerGM::get($frame->fd);
|
||||
set_coroutine_params(['server' => $server, 'frame' => $frame, 'connection' => $conn]);
|
||||
|
||||
@@ -29,7 +29,7 @@ class OnOpen implements SwooleEvent
|
||||
{
|
||||
public function onCall($server, Request $request)
|
||||
{
|
||||
Console::debug('Calling Swoole "open" event from fd=' . $request->fd);
|
||||
logger()->debug('Calling Swoole "open" event from fd=' . $request->fd);
|
||||
unset(Context::$context[Coroutine::getCid()]);
|
||||
|
||||
$type = strtolower($request->header['x-client-role'] ?? $request->get['type'] ?? '');
|
||||
@@ -38,13 +38,13 @@ class OnOpen implements SwooleEvent
|
||||
if ($token instanceof Closure) {
|
||||
if (!$token($access_token)) {
|
||||
$server->close($request->fd);
|
||||
Console::warning(zm_internal_errcode('E00018') . 'Unauthorized access_token: ' . $access_token);
|
||||
logger()->warning(zm_internal_errcode('E00018') . 'Unauthorized access_token: ' . $access_token);
|
||||
return;
|
||||
}
|
||||
} elseif (is_string($token)) {
|
||||
if ($access_token !== $token && $token !== '') {
|
||||
$server->close($request->fd);
|
||||
Console::warning(zm_internal_errcode('E00019') . 'Unauthorized access_token: ' . $access_token);
|
||||
logger()->warning(zm_internal_errcode('E00019') . 'Unauthorized access_token: ' . $access_token);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ class OnRequest implements SwooleEvent
|
||||
$response->setHeader($k, $v);
|
||||
}
|
||||
unset(Context::$context[Coroutine::getCid()]);
|
||||
Console::debug('Calling Swoole "request" event from fd=' . $request->fd);
|
||||
logger()->debug('Calling Swoole "request" event from fd=' . $request->fd);
|
||||
set_coroutine_params(['request' => $request, 'response' => $response]);
|
||||
|
||||
resolve(ContainerServicesProvider::class)->registerServices('request');
|
||||
@@ -83,7 +83,7 @@ class OnRequest implements SwooleEvent
|
||||
// do nothing
|
||||
} catch (Exception $e) {
|
||||
$response->status(500);
|
||||
Console::info(
|
||||
logger()->info(
|
||||
$request->server['remote_addr'] . ':' . $request->server['remote_port'] .
|
||||
' [' . $response->getStatusCode() . '] ' . $request->server['request_uri']
|
||||
);
|
||||
@@ -98,7 +98,7 @@ class OnRequest implements SwooleEvent
|
||||
Console::log($e->getTraceAsString(), 'gray');
|
||||
} catch (Error $e) {
|
||||
$response->status(500);
|
||||
Console::info(
|
||||
logger()->info(
|
||||
$request->server['remote_addr'] . ':' . $request->server['remote_port'] .
|
||||
' [' . $response->getStatusCode() . '] ' . $request->server['request_uri']
|
||||
);
|
||||
|
||||
@@ -8,7 +8,6 @@ namespace ZM\Event\SwooleEvent;
|
||||
|
||||
use Swoole\Server;
|
||||
use ZM\Annotation\Swoole\SwooleHandler;
|
||||
use ZM\Console\Console;
|
||||
use ZM\Event\SwooleEvent;
|
||||
use ZM\Utils\DataProvider;
|
||||
use ZM\Utils\Manager\ProcessManager;
|
||||
@@ -21,7 +20,7 @@ class OnShutdown implements SwooleEvent
|
||||
{
|
||||
public function onCall(Server $server)
|
||||
{
|
||||
Console::verbose('正在关闭 Master 进程,pid=' . posix_getpid());
|
||||
logger()->debug('正在关闭 Master 进程,pid=' . posix_getpid());
|
||||
ProcessManager::removeProcessState(ZM_PROCESS_MASTER);
|
||||
if (DataProvider::scanDirFiles(_zm_pid_dir()) == []) {
|
||||
rmdir(_zm_pid_dir());
|
||||
|
||||
@@ -7,7 +7,6 @@ namespace ZM\Event\SwooleEvent;
|
||||
use Swoole\Server;
|
||||
use ZM\Annotation\Swoole\SwooleHandler;
|
||||
use ZM\Config\ZMConfig;
|
||||
use ZM\Console\Console;
|
||||
use ZM\Event\SwooleEvent;
|
||||
use ZM\Framework;
|
||||
use ZM\Utils\Manager\ProcessManager;
|
||||
@@ -21,7 +20,7 @@ class OnStart implements SwooleEvent
|
||||
{
|
||||
public function onCall(Server $server)
|
||||
{
|
||||
Console::debug('Calling onStart event(1)');
|
||||
logger()->debug('Calling onStart event(1)');
|
||||
if (!Framework::$argv['disable-safe-exit']) {
|
||||
SignalListener::signalMaster($server);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ use Swoole\Coroutine;
|
||||
use Swoole\Server;
|
||||
use Swoole\Timer;
|
||||
use ZM\Annotation\Swoole\SwooleHandler;
|
||||
use ZM\Console\Console;
|
||||
use ZM\Event\SwooleEvent;
|
||||
use ZM\Store\LightCacheInside;
|
||||
|
||||
@@ -28,6 +27,6 @@ class OnWorkerExit implements SwooleEvent
|
||||
Coroutine::resume($v['coroutine']);
|
||||
}
|
||||
}
|
||||
Console::verbose('正在结束 Worker #' . $worker_id . ',进程内可能有事务在运行...');
|
||||
logger()->debug('正在结束 Worker #' . $worker_id . ',进程内可能有事务在运行...');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ class OnWorkerStart implements SwooleEvent
|
||||
{
|
||||
public function onCall(Server $server, int $worker_id)
|
||||
{
|
||||
Console::debug('Calling onWorkerStart event(1)');
|
||||
logger()->debug('Calling onWorkerStart event(1)');
|
||||
if (!Framework::$argv['disable-safe-exit']) {
|
||||
SignalListener::signalWorker($server, $worker_id);
|
||||
}
|
||||
@@ -79,7 +79,7 @@ class OnWorkerStart implements SwooleEvent
|
||||
$server->shutdown();
|
||||
});
|
||||
|
||||
Console::verbose("Worker #{$server->worker_id} starting");
|
||||
logger()->debug("Worker #{$server->worker_id} starting");
|
||||
// ZMBuf::resetCache(); //清空变量缓存
|
||||
// ZMBuf::set("wait_start", []); //添加队列,在workerStart运行完成前先让其他协程等待执行
|
||||
|
||||
@@ -107,11 +107,11 @@ class OnWorkerStart implements SwooleEvent
|
||||
});
|
||||
$dispatcher->dispatchEvents($server, $worker_id);
|
||||
if ($dispatcher->status === EventDispatcher::STATUS_NORMAL) {
|
||||
Console::debug('@OnStart 执行完毕');
|
||||
logger()->debug('@OnStart 执行完毕');
|
||||
} else {
|
||||
Console::warning('@OnStart 执行异常!');
|
||||
logger()->warning('@OnStart 执行异常!');
|
||||
}
|
||||
Console::verbose('Worker #' . $worker_id . ' started');
|
||||
logger()->debug('Worker #' . $worker_id . ' started');
|
||||
$this->gatherWorkerStartStatus();
|
||||
} catch (Exception $e) {
|
||||
if ($e->getMessage() === 'swoole exit') {
|
||||
@@ -134,7 +134,7 @@ class OnWorkerStart implements SwooleEvent
|
||||
ProcessManager::saveProcessState(ZM_PROCESS_TASKWORKER, $server->worker_pid, ['worker_id' => $worker_id]);
|
||||
try {
|
||||
$this->loadAnnotations();
|
||||
Console::verbose('TaskWorker #' . $server->worker_id . ' started');
|
||||
logger()->debug('TaskWorker #' . $server->worker_id . ' started');
|
||||
} catch (Exception $e) {
|
||||
Console::error('TaskWorker #' . $server->worker_id . ' 加载出错!停止服务!');
|
||||
Console::error(zm_internal_errcode('E00030') . $e->getMessage() . "\n" . $e->getTraceAsString());
|
||||
@@ -159,7 +159,7 @@ class OnWorkerStart implements SwooleEvent
|
||||
goto skip;
|
||||
}
|
||||
// 加载各个模块的注解类,以及反射
|
||||
Console::debug('Mapping annotations');
|
||||
logger()->debug('Mapping annotations');
|
||||
$parser = new AnnotationParser();
|
||||
$composer = json_decode(file_get_contents(DataProvider::getSourceRootDir() . '/composer.json'), true);
|
||||
$merge = array_merge($composer['autoload']['psr-4'] ?? [], $composer['autoload-dev']['psr-4'] ?? []);
|
||||
@@ -182,7 +182,7 @@ class OnWorkerStart implements SwooleEvent
|
||||
$list = ModuleManager::getPackedModules();
|
||||
foreach ($list as $k => $v) {
|
||||
if (\server()->worker_id === 0) {
|
||||
Console::info('Loading packed module: ' . $k);
|
||||
logger()->info('Loading packed module: ' . $k);
|
||||
}
|
||||
require_once $v['phar-path'];
|
||||
$func = 'loader' . $v['generated-id'];
|
||||
@@ -195,7 +195,7 @@ class OnWorkerStart implements SwooleEvent
|
||||
$list = ModuleManager::getComposerModules();
|
||||
foreach ($list as $k => $v) {
|
||||
if (\server()->worker_id === 0) {
|
||||
Console::info('Loading composer module: ' . $k);
|
||||
logger()->info('Loading composer module: ' . $k);
|
||||
}
|
||||
$parser->addRegisterPath($v['module-path'], $v['namespace']);
|
||||
}
|
||||
@@ -205,7 +205,7 @@ class OnWorkerStart implements SwooleEvent
|
||||
|
||||
skip:
|
||||
// 加载自定义的全局函数
|
||||
Console::debug('Loading context class...');
|
||||
logger()->debug('Loading context class...');
|
||||
$context_class = ZMConfig::get('global', 'context_class');
|
||||
if (!is_a($context_class, ContextInterface::class, true)) {
|
||||
throw new ZMKnownException('E00032', 'Context class must implemented from ContextInterface!');
|
||||
@@ -215,7 +215,7 @@ class OnWorkerStart implements SwooleEvent
|
||||
ZMConfig::get('global', 'modules')['onebot'] ??
|
||||
['status' => true, 'single_bot_mode' => false, 'message_level' => 99999];
|
||||
if ($obb_onebot['status']) {
|
||||
Console::debug('OneBot support enabled, listening OneBot event(3).');
|
||||
logger()->debug('OneBot support enabled, listening OneBot event(3).');
|
||||
$obj = new OnMessageEvent();
|
||||
$obj->connect_type = 'qq';
|
||||
$obj->class = AdapterInterface::class;
|
||||
@@ -240,8 +240,8 @@ class OnWorkerStart implements SwooleEvent
|
||||
if (isset(ZMConfig::get('global', 'sql_config')['sql_host'])) {
|
||||
if (ZMConfig::get('global', 'sql_config')['sql_host'] != '') {
|
||||
if (\server()->worker_id === 0) {
|
||||
Console::warning("使用 'sql_config' 配置项和 DB 数据库查询构造器进行查询数据库可能会在下一个大版本中废弃,请使用 'mysql_config' 搭配 doctrine dbal 使用!");
|
||||
Console::warning('详见: `https://framework.zhamao.xin/`');
|
||||
logger()->warning("使用 'sql_config' 配置项和 DB 数据库查询构造器进行查询数据库可能会在下一个大版本中废弃,请使用 'mysql_config' 搭配 doctrine dbal 使用!");
|
||||
logger()->warning('详见: `https://framework.zhamao.xin/`');
|
||||
}
|
||||
$origin_conf = ZMConfig::get('global', 'sql_config');
|
||||
$real_conf = [
|
||||
@@ -263,7 +263,7 @@ class OnWorkerStart implements SwooleEvent
|
||||
}
|
||||
}
|
||||
if (!empty($real_conf)) {
|
||||
Console::info('Connecting to MySQL pool');
|
||||
logger()->info('Connecting to MySQL pool');
|
||||
ob_start();
|
||||
phpinfo(); // 这个phpinfo是有用的,不能删除
|
||||
$str = ob_get_clean();
|
||||
@@ -305,7 +305,7 @@ class OnWorkerStart implements SwooleEvent
|
||||
SpinLock::unlock('worker_start_status');
|
||||
$used = round((microtime(true) - LightCacheInside::get('tmp_kv', 'start_time')) * 1000, 3);
|
||||
$worker_count = \server()->setting['worker_num'];
|
||||
Console::success("{$worker_count} 个工作进程成功启动,共用时 {$used} ms");
|
||||
logger()->info("{$worker_count} 个工作进程成功启动,共用时 {$used} ms");
|
||||
} else {
|
||||
LightCacheInside::set('tmp_kv', 'worker_start_status', $ls);
|
||||
SpinLock::unlock('worker_start_status');
|
||||
|
||||
@@ -7,7 +7,6 @@ namespace ZM\Event\SwooleEvent;
|
||||
use Swoole\Server;
|
||||
use ZM\Annotation\Swoole\SwooleHandler;
|
||||
use ZM\Config\ZMConfig;
|
||||
use ZM\Console\Console;
|
||||
use ZM\Event\SwooleEvent;
|
||||
use ZM\Store\LightCache;
|
||||
use ZM\Utils\Manager\ProcessManager;
|
||||
@@ -23,7 +22,7 @@ class OnWorkerStop implements SwooleEvent
|
||||
if ($worker_id == (ZMConfig::get('global.worker_cache.worker') ?? 0)) {
|
||||
LightCache::savePersistence();
|
||||
}
|
||||
Console::verbose(($server->taskworker ? 'Task' : '') . "Worker #{$worker_id} 已停止 (Worker 状态码: " . $server->getWorkerStatus($worker_id) . ')');
|
||||
logger()->debug('{worker}#{worker_id} 已停止(状态码:{status})', ['worker' => ($server->taskworker ? 'Task' : '') . 'Worker', 'worker_id' => $worker_id, 'status' => $server->getWorkerStatus($worker_id)]);
|
||||
ProcessManager::removeProcessState($server->taskworker ? ZM_PROCESS_TASKWORKER : ZM_PROCESS_WORKER, $worker_id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user