diff --git a/Abstracts/AsyncServer.php b/Abstracts/AsyncServer.php index 70809fb..ba85902 100644 --- a/Abstracts/AsyncServer.php +++ b/Abstracts/AsyncServer.php @@ -4,16 +4,13 @@ namespace Kiri\Server\Abstracts; use Exception; use Kiri; -use Kiri\Abstracts\Logger; use Kiri\Exception\ConfigException; use Kiri\Exception\NotFindClassException; use Kiri\Server\Config as SConfig; use Kiri\Server\Constant; use Kiri\Server\Events\OnServerBeforeStart; use Kiri\Server\Events\OnShutdown; -use Kiri\Server\Events\OnWorkerStart; use Kiri\Server\Handler\OnServer; -use Kiri\Server\HotReload; use Kiri\Server\ServerInterface; use Kiri\Server\Task\TaskInterface; use Kiri\Server\Task\Task; diff --git a/Abstracts/BaseProcess.php b/Abstracts/BaseProcess.php index f97cd52..ff7ef9c 100644 --- a/Abstracts/BaseProcess.php +++ b/Abstracts/BaseProcess.php @@ -3,9 +3,11 @@ namespace Kiri\Server\Abstracts; -use Kiri\Abstracts\Logger; use Kiri\Di\Context; +use Kiri\Di\Inject\Container; use Kiri\Server\Contract\OnProcessInterface; +use Monolog\Logger; +use Psr\Log\LoggerInterface; use Swoole\Coroutine; /** @@ -26,6 +28,13 @@ abstract class BaseProcess implements OnProcessInterface protected bool $enable_coroutine = false; + /** + * @var Logger + */ + #[Container(LoggerInterface::class)] + public Logger $logger; + + public string $name = ''; @@ -97,7 +106,7 @@ abstract class BaseProcess implements OnProcessInterface { $this->isStop = true; $value = Context::get('waite:process:message'); - Logger::_alert('Process ' . $this->getName() . ' stop'); + $this->logger->alert('Process ' . $this->getName() . ' stop'); if (!is_null($value) && Coroutine::exists((int)$value)) { Coroutine::cancel((int)$value); } diff --git a/Abstracts/ProcessManager.php b/Abstracts/ProcessManager.php index d30a503..70ff533 100644 --- a/Abstracts/ProcessManager.php +++ b/Abstracts/ProcessManager.php @@ -6,10 +6,12 @@ use Closure; use Exception; use Kiri; use Kiri\Abstracts\Component; +use Kiri\Di\Inject\Container; use Kiri\Server\Contract\OnProcessInterface; +use Monolog\Logger; +use Psr\Log\LoggerInterface; use ReflectionException; use Swoole\Process; -use Kiri\Abstracts\Logger; use Kiri\Server\ServerInterface; use Kiri\Server\Events\OnServerBeforeStart; @@ -17,6 +19,13 @@ class ProcessManager extends Component { + /** + * @var Logger + */ + #[Container(LoggerInterface::class)] + public Logger $logger; + + /** @var array */ private array $_process = []; @@ -174,7 +183,7 @@ class ProcessManager extends Component { set_env('environmental', Kiri::PROCESS); $system = sprintf('[%s].Custom Process', \config('id', 'system-service')); - Logger::_alert($system . ' ' . $custom->getName() . ' start.'); + $this->logger->alert($system . ' ' . $custom->getName() . ' start.'); if (Kiri::getPlatform()->isLinux()) { $process->name($system . '[' . $process->pid . '].' . $custom->getName()); } diff --git a/Abstracts/TraitServer.php b/Abstracts/TraitServer.php index 89f6f83..881a380 100644 --- a/Abstracts/TraitServer.php +++ b/Abstracts/TraitServer.php @@ -4,9 +4,9 @@ namespace Kiri\Server\Abstracts; use Exception; use Kiri; -use Kiri\Abstracts\Logger; -use ReflectionException; -use Swoole\Coroutine; +use Kiri\Di\Inject\Container; +use Monolog\Logger; +use Psr\Log\LoggerInterface; use Swoole\Http\Server as HServer; use Swoole\Process; use Swoole\Server; @@ -21,6 +21,14 @@ trait TraitServer private array $_process = []; + + /** + * @var Logger + */ + #[Container(LoggerInterface::class)] + public Logger $logger; + + /** * @param string|array|BaseProcess $class * @return void @@ -87,7 +95,7 @@ trait TraitServer public function onSigint($no, array $signInfo): void { try { - Logger::_alert('Pid ' . getmypid() . ' get signo ' . $no); + $this->logger->alert('Pid ' . getmypid() . ' get signo ' . $no); $this->shutdown(); } catch (\Throwable $exception) { error($exception); diff --git a/Handler/OnServer.php b/Handler/OnServer.php index 966143c..cc40418 100644 --- a/Handler/OnServer.php +++ b/Handler/OnServer.php @@ -2,14 +2,11 @@ namespace Kiri\Server\Handler; -use Kiri\Abstracts\Logger; use Kiri\Di\Inject\Container; -use Kiri\Events\EventDispatch; -use Kiri\Exception\ConfigException; -use Kiri\Server\Events\OnAfterReload; -use Kiri\Server\Events\OnBeforeReload; +use Monolog\Logger; use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; +use Psr\Log\LoggerInterface; use ReflectionException; use Kiri\Server\Abstracts\Server; use Kiri\Server\Events\OnBeforeShutdown; @@ -26,6 +23,13 @@ class OnServer extends Server { + /** + * @var Logger + */ + #[Container(LoggerInterface::class)] + public Logger $logger; + + /** * @param SServer $server * @throws ReflectionException @@ -36,7 +40,7 @@ class OnServer extends Server { \Kiri::setProcessName(sprintf('start[%d].server', $server->master_pid)); foreach (config('server.ports') as $value) { - Logger::_alert('Listen ' . $value['type'] . ' address ' . $value['host'] . '::' . $value['port']); + $this->logger->alert('Listen ' . $value['type'] . ' address ' . $value['host'] . '::' . $value['port']); } event(new OnStart($server)); } diff --git a/State.php b/State.php index 8828ad9..aa4fe7a 100644 --- a/State.php +++ b/State.php @@ -4,7 +4,6 @@ namespace Kiri\Server; use Exception; use Kiri\Abstracts\Component; -use Kiri\Abstracts\Logger; use Kiri\Server\Abstracts\TraitServer; use Swoole\Process;