diff --git a/HttpServer/Service/Abstracts/Server.php b/HttpServer/Service/Abstracts/Server.php index 33f6e41b..4049a802 100644 --- a/HttpServer/Service/Abstracts/Server.php +++ b/HttpServer/Service/Abstracts/Server.php @@ -13,8 +13,7 @@ use Snowflake\Snowflake; trait Server { - /** @var Application */ - public $application; + public ?Application $application = null; /** @@ -26,7 +25,6 @@ trait Server */ public function __construct($host, $port = null, $mode = null, $sock_type = null) { - $this->application = Snowflake::app(); parent::__construct($host, $port, $mode, $sock_type); } diff --git a/Kafka/Kafka.php b/Kafka/Kafka.php index 447aff9a..5c83e0ff 100644 --- a/Kafka/Kafka.php +++ b/Kafka/Kafka.php @@ -86,11 +86,11 @@ class Kafka extends \Snowflake\Process\Process if ($message->err == RD_KAFKA_RESP_ERR_NO_ERROR) { $this->handlerExecute($message->topic_name, $message); } else if ($message->err == RD_KAFKA_RESP_ERR__PARTITION_EOF) { - $this->application->warning('No more messages; will wait for more'); + logger()->warning('No more messages; will wait for more'); } else if ($message->err == RD_KAFKA_RESP_ERR__TIMED_OUT) { - $this->application->error('Kafka Timed out'); + logger()->error('Kafka Timed out'); } else { - $this->application->error($message->errstr()); + logger()->error($message->errstr()); } } catch (Throwable $exception) { logger()->addError($exception, 'throwable'); @@ -142,8 +142,8 @@ class Kafka extends \Snowflake\Process\Process $conf->set('metadata.broker.list', $kafka['brokers']); $conf->set('socket.timeout.ms', '30000'); - $this->application->debug('kafka listen groupId ' . $kafka['groupId']); - $this->application->debug('kafka listen brokers ' . $kafka['brokers']); + logger()->debug('kafka listen groupId ' . $kafka['groupId']); + logger()->debug('kafka listen brokers ' . $kafka['brokers']); if (function_exists('pcntl_sigprocmask')) { pcntl_sigprocmask(SIG_BLOCK, array(SIGIO)); diff --git a/System/Process/Process.php b/System/Process/Process.php index dc9bcdbd..cc14e5e7 100644 --- a/System/Process/Process.php +++ b/System/Process/Process.php @@ -34,7 +34,6 @@ abstract class Process extends \Swoole\Process implements SProcess public function __construct($application, $name, $enable_coroutine = true) { parent::__construct([$this, '_load'], false, 1, $enable_coroutine); - $this->application = $application; Snowflake::setProcessId($this->pid); } diff --git a/System/Process/ServerInotify.php b/System/Process/ServerInotify.php index 97c72113..4a0f5588 100644 --- a/System/Process/ServerInotify.php +++ b/System/Process/ServerInotify.php @@ -265,8 +265,8 @@ class ServerInotify extends Process if (str_contains($message, 'The file descriptor is not an inotify instance')) { return; } - $this->application->debug('Error:' . $message); - $this->application->debug($file . ':' . $line); + logger()->debug('Error:' . $message); + logger()->debug($file . ':' . $line); } @@ -279,7 +279,7 @@ class ServerInotify extends Process { //目录不存在 if (!is_dir($dir)) { - return $this->application->addError("[$dir] is not a directory."); + return logger()->addError("[$dir] is not a directory."); } //避免重复监听 if (isset($this->watchFiles[$dir])) {