diff --git a/src/API/TriggerEvent.php b/src/API/TriggerEvent.php index b512027..4e29353 100644 --- a/src/API/TriggerEvent.php +++ b/src/API/TriggerEvent.php @@ -6,6 +6,7 @@ use BeyondCode\LaravelWebSockets\DashboardLogger; use BeyondCode\LaravelWebSockets\Facades\StatisticsCollector; use Illuminate\Http\Request; use React\Promise\Deferred; +use React\Promise\PromiseInterface; class TriggerEvent extends Controller { @@ -13,7 +14,7 @@ class TriggerEvent extends Controller * Handle the incoming request. * * @param \Illuminate\Http\Request $request - * @return \Illuminate\Http\Response + * @return PromiseInterface */ public function __invoke(Request $request) { diff --git a/src/Console/Commands/StartServer.php b/src/Console/Commands/StartServer.php index 69ea1ff..429b478 100644 --- a/src/Console/Commands/StartServer.php +++ b/src/Console/Commands/StartServer.php @@ -13,6 +13,7 @@ use Illuminate\Console\Command; use Illuminate\Support\Facades\Cache; use React\EventLoop\Factory as LoopFactory; use React\EventLoop\LoopInterface; +use Symfony\Component\Console\Output\OutputInterface; use function React\Promise\all; class StartServer extends Command @@ -134,7 +135,7 @@ class StartServer extends Command $intervalInSeconds = $this->option('statistics-interval') ?: config('websockets.statistics.interval_in_seconds', 3600); $this->loop->addPeriodicTimer($intervalInSeconds, function () { - $this->line('Saving statistics...'); + $this->line('Saving statistics...', null, OutputInterface::VERBOSITY_VERBOSE); StatisticsCollectorFacade::save(); }); @@ -260,7 +261,9 @@ class StartServer extends Command */ protected function startServer() { - $this->info("Starting the WebSocket server on port {$this->option('port')}..."); + $this->components->info("Starting the WebSocket server on port {$this->option('port')}..."); + $this->comment(' Press Ctrl+C to stop the server'); + $this->newLine(); $this->buildServer(); diff --git a/src/Server/Loggers/ConnectionLogger.php b/src/Server/Loggers/ConnectionLogger.php index 60e2ffb..62d2bb5 100644 --- a/src/Server/Loggers/ConnectionLogger.php +++ b/src/Server/Loggers/ConnectionLogger.php @@ -48,8 +48,9 @@ class ConnectionLogger extends Logger implements ConnectionInterface public function send($data) { $socketId = $this->connection->socketId ?? null; + $appId = $this->connection->app->id ?? null; - $this->info("Connection id {$socketId} sending message {$data}"); + $this->info("[{$appId}][{$socketId}] Sending message ". ($this->verbose ? $data : '')); $this->connection->send($data); } @@ -61,7 +62,10 @@ class ConnectionLogger extends Logger implements ConnectionInterface */ public function close() { - $this->warn("Connection id {$this->connection->socketId} closing."); + $socketId = $this->connection->socketId ?? null; + $appId = $this->connection->app->id ?? null; + + $this->warn("[{$appId}][{$socketId}] Closing connection"); $this->connection->close(); } diff --git a/src/Server/Loggers/WebSocketsLogger.php b/src/Server/Loggers/WebSocketsLogger.php index a9555e1..56e7c1a 100644 --- a/src/Server/Loggers/WebSocketsLogger.php +++ b/src/Server/Loggers/WebSocketsLogger.php @@ -53,7 +53,7 @@ class WebSocketsLogger extends Logger implements MessageComponentInterface { $appKey = QueryParameters::create($connection->httpRequest)->get('appKey'); - $this->warn("New connection opened for app key {$appKey}."); + $this->info("[$appKey] New connection opened."); $this->app->onOpen(ConnectionLogger::decorate($connection)); } @@ -67,7 +67,7 @@ class WebSocketsLogger extends Logger implements MessageComponentInterface */ public function onMessage(ConnectionInterface $connection, MessageInterface $message) { - $this->info("{$connection->app->id}: connection id {$connection->socketId} received message: {$message->getPayload()}."); + $this->info("[{$connection->app->id}][{$connection->socketId}] Received message ". ($this->verbose ? $message->getPayload() : '')); $this->app->onMessage(ConnectionLogger::decorate($connection), $message); } @@ -81,8 +81,9 @@ class WebSocketsLogger extends Logger implements MessageComponentInterface public function onClose(ConnectionInterface $connection) { $socketId = $connection->socketId ?? null; + $appId = $connection->app->id ?? null; - $this->warn("Connection id {$socketId} closed."); + $this->warn("[{$appId}][{$socketId}] Connection closed"); $this->app->onClose(ConnectionLogger::decorate($connection)); } @@ -100,7 +101,7 @@ class WebSocketsLogger extends Logger implements MessageComponentInterface $appId = $connection->app->id ?? 'Unknown app id'; - $message = "{$appId}: exception `{$exceptionClass}` thrown: `{$exception->getMessage()}`."; + $message = "[{$appId}] Exception `{$exceptionClass}` thrown: `{$exception->getMessage()}`"; if ($this->verbose) { $message .= $exception->getTraceAsString();