logger = $loggerFactory->get('queue'); $this->formatter = $formatter; } public function listen(): array { return [ AfterHandle::class, BeforeHandle::class, FailedHandle::class, RetryHandle::class, ]; } public function process(object $event) { if ($event instanceof Event && $event->message->job()) { $job = $event->message->job(); $jobClass = get_class($job); $date = date('Y-m-d H:i:s'); switch (true) { case $event instanceof BeforeHandle: $this->logger->info(sprintf('[%s] Processing %s.', $date, $jobClass)); break; case $event instanceof AfterHandle: $this->logger->info(sprintf('[%s] Processed %s.', $date, $jobClass)); break; case $event instanceof FailedHandle: $this->logger->error(sprintf('[%s] Failed %s.', $date, $jobClass)); $this->logger->error($this->formatter->format($event->getThrowable())); break; case $event instanceof RetryHandle: $this->logger->warning(sprintf('[%s] Retried %s.', $date, $jobClass)); break; } } } }