diff --git a/src/Application/LoggerAwareApplication.php b/src/Application/LoggerAwareApplication.php new file mode 100644 index 0000000..0a4a9ba --- /dev/null +++ b/src/Application/LoggerAwareApplication.php @@ -0,0 +1,29 @@ +logger = new NullLogger(); + } + + public function setLogger(LoggerInterface $logger): void + { + $this->logger = $logger; + } + + protected function getLogger(): LoggerInterface + { + return $this->logger; + } +} diff --git a/src/Application/StatusApplication.php b/src/Application/StatusApplication.php index 067d9e1..724b7ed 100644 --- a/src/Application/StatusApplication.php +++ b/src/Application/StatusApplication.php @@ -6,7 +6,7 @@ use Bloatless\WebSocket\Connection; -class StatusApplication extends Application +class StatusApplication extends LoggerAwareApplication { /** * Holds client connected to the status application. @@ -164,6 +164,7 @@ public function statusMsg(string $text, string $type = 'info'): void ]; $encodedData = $this->encodeData('statusMsg', $data); $this->sendAll($encodedData); + $this->getLogger()->log($type, 'Status message: ' . $text); } /** diff --git a/src/Server.php b/src/Server.php index 4ad301b..d151fa8 100644 --- a/src/Server.php +++ b/src/Server.php @@ -5,6 +5,7 @@ namespace Bloatless\WebSocket; use Bloatless\WebSocket\Application\ApplicationInterface; +use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerInterface; /** @@ -142,7 +143,7 @@ public function run(): void while (true) { $this->timers->runAll(); - + $changed_sockets = $this->allsockets; @stream_select($changed_sockets, $write, $except, 0, 5000); foreach ($changed_sockets as $socket) { @@ -247,6 +248,10 @@ public function registerApplication(string $key, ApplicationInterface $applicati { $this->applications[$key] = $application; + if ($application instanceof LoggerAwareInterface) { + $application->setLogger($this->logger); + } + // status is kind of a system-app, needs some special cases: if ($key === 'status') { $serverInfo = array(