-
Notifications
You must be signed in to change notification settings - Fork 4
/
ExceptionLogger.php
47 lines (41 loc) · 1.07 KB
/
ExceptionLogger.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
namespace LastCall\Crawler\Handler\Logging;
use LastCall\Crawler\CrawlerEvents;
use LastCall\Crawler\Event\CrawlerExceptionEvent;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Logs exceptions to a PSR-3 compatible logger.
*/
class ExceptionLogger implements EventSubscriberInterface
{
/**
* @var \Psr\Log\LoggerInterface
*/
private $logger;
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents()
{
return [
CrawlerEvents::EXCEPTION => 'onCrawlerException',
];
}
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
}
/**
* Log exception events.
*
* @param \LastCall\Crawler\Event\CrawlerExceptionEvent $event
*/
public function onCrawlerException(CrawlerExceptionEvent $event)
{
$this->logger->critical($event->getException(), [
'exception' => $event->getException(),
'url' => $event->getRequest()->getUri(),
]);
}
}