diff --git a/src/Connection.php b/src/Connection.php index 90e988c..3fe6860 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -43,17 +43,9 @@ abstract class Connection private LoggerInterface $logger, ) { $this->stream = new NullStream(); - $this->onConnectCallback = static function () use ($logger, $address) { - $logger->debug('Connected.', [ - 'class' => static::class, - 'address' => $address, - ]); + $this->onConnectCallback = static function () { }; - $this->onCloseCallback = static function () use ($logger, $address) { - $logger->debug('Disconnected.', [ - 'class' => static::class, - 'address' => $address, - ]); + $this->onCloseCallback = static function () { }; } diff --git a/src/Consumer.php b/src/Consumer.php index dc94c5b..05641bd 100644 --- a/src/Consumer.php +++ b/src/Consumer.php @@ -38,6 +38,15 @@ final class Consumer extends Connection ); $this->onMessage = $onMessage; + + $context = compact('address', 'topic', 'channel'); + $this->onConnect(function () use ($context) { + $this->logger->debug('Consumer connected.', $context); + }); + $this->onClose(function () use ($context) { + $this->logger->debug('Consumer disconnected.', $context); + }); + $this->logger->debug('Consumer created.', $context); } public static function create( @@ -68,12 +77,6 @@ final class Consumer extends Connection return call(function (): \Generator { yield parent::connect(); - $this->logger->debug('Consumer {topic}:{channel} connected to {host}', [ - 'topic' => $this->topic, - 'channel' => $this->channel, - 'host' => $this->address, - ]); - $this->run(); }); } @@ -129,12 +132,6 @@ final class Consumer extends Connection } } - $this->logger->debug('Consumer disconnected.', [ - 'address' => $this->address, - 'topic' => $this->topic, - 'channel' => $this->channel, - ]); - $this->close(false); }); }); diff --git a/src/Lookup.php b/src/Lookup.php index bd70444..f3442e0 100644 --- a/src/Lookup.php +++ b/src/Lookup.php @@ -144,8 +144,6 @@ final class Lookup unset($consumers[$consumerKey]); })->connect(); - $this->logger->debug('Consumer created.', compact('address', 'topic', 'channel')); - $promise->onResolve(function (?\Throwable $e) use ($consumerKey, &$consumers) { if (null !== $e) { $this->logger->error($e->getMessage()); @@ -163,13 +161,13 @@ final class Lookup $this->watch($topic); - $this->logger->info('Subscribed', compact('topic', 'channel')); + $this->logger->info('Subscribed.', compact('topic', 'channel')); } public function unsubscribe(string $topic, string $channel): void { if (null === ($this->running[$topic][$channel] ?? null)) { - $this->logger->debug('Trying unsubscribe from non subscribed', compact('topic', 'channel')); + $this->logger->debug('Not subscribed.', compact('topic', 'channel')); return; } @@ -180,7 +178,7 @@ final class Lookup unset($this->running[$topic]); } - $this->logger->info('Unsubscribed', compact('topic', 'channel')); + $this->logger->info('Unsubscribed.', compact('topic', 'channel')); } private function watch(string $topic): void diff --git a/src/Producer.php b/src/Producer.php index 0558dab..da9a011 100644 --- a/src/Producer.php +++ b/src/Producer.php @@ -24,6 +24,15 @@ final class Producer extends Connection $this->clientConfig, $this->logger, ); + + $context = compact('address'); + $this->onConnect(function () use ($context) { + $this->logger->debug('Producer connected.', $context); + }); + $this->onClose(function () use ($context) { + $this->logger->debug('Producer disconnected.', $context); + }); + $this->logger->debug('Producer created.', $context); } public static function create( @@ -48,10 +57,6 @@ final class Producer extends Connection return call(function (): \Generator { yield parent::connect(); - $this->logger->debug('Producer connected to {host}', [ - 'host' => $this->address, - ]); - $this->run(); }); }