Refactor logging

This commit is contained in:
2021-09-18 22:47:06 +03:00
parent c8cd41777f
commit 97b3d8206c
4 changed files with 23 additions and 31 deletions

View File

@@ -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);
});
});