-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove logs #21
Comments
For this, I believe that the best would be to add some sort of event propagation and let the user add "subscribers" to handle those events. Then, we could create a default event subscriber that implements the same logging logic of today in order to allow for a smoother transition and keeping the current behaviour as it is. I would suggest for us to implement something similar to what Ganesha does. As an example, today we log any consumer errors (code extracted from our Consumer class): if (!in_array($message->err, self::IGNORABLE_CONSUME_ERRORS)) {
$this->logger->error($message, null, 'CONSUMER');
throw new KafkaConsumerException($message->errstr(), $message->err);
} We could internally replace this with the following: if (!in_array($message->err, self::IGNORABLE_CONSUME_ERRORS)) {
$this->eventDispatcher->dispatch(new FailedToConsumeMessage($message));
throw new KafkaConsumerException($message->errstr(), $message->err);
} This dispatcher component could be something like the following: <?php
declare(strict_types=1);
namespace Kafka\Consumer;
class EventDispatcher
{
private $subscribers;
public function __construct(array $subscribers)
{
$this->subscribers = $subscribers;
}
public function dispatch($event): void
{
// Get all subscribers for the given event
$subscribers = $this->subscribers[get_class($event)] ?? [];
// Execute every subscriber
foreach ($subscribers as $subscriber) {
$subscriber($event);
}
}
} Then, the user could provide any callable as a subscriber to handle that type of event: $subscriber = function (FailedToConsumeMessage $event) {
$logger->error($message, null, 'CONSUMER');
}; |
Implement the concept of events and create a event subscriber to dispatch events. Extract logging logic from the consumer into an event subscriber in order to decouple logging logic from the consumer class. Fixes #21
The job of communicating errors is well performed by the throwing of exceptions. Every user has different log requirements and catering to all of them is beyond the scope of this project. The need for this log is up for discussion, but as of right now, the proposal is to remove them. |
Logging errors and other things should be a responsibility for the user. I move we remove logs and use exceptions where it makes sense.
The text was updated successfully, but these errors were encountered: