2015-07-24 00:53:41 +02:00
|
|
|
<?php
|
|
|
|
|
2016-08-19 00:51:35 +02:00
|
|
|
namespace SilverStripe\Logging;
|
2015-07-24 00:53:41 +02:00
|
|
|
|
|
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
use Monolog\ErrorHandler;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Simple adaptor to start Monolog\ErrorHandler
|
|
|
|
*/
|
|
|
|
class MonologErrorHandler
|
|
|
|
{
|
2017-03-09 23:20:58 +01:00
|
|
|
/**
|
|
|
|
* @var LoggerInterface
|
|
|
|
*/
|
2016-11-29 00:31:16 +01:00
|
|
|
private $logger;
|
2015-07-24 00:53:41 +02:00
|
|
|
|
2016-11-29 00:31:16 +01:00
|
|
|
/**
|
|
|
|
* Set the PSR-3 logger to send errors & exceptions to
|
2017-03-09 23:20:58 +01:00
|
|
|
*
|
|
|
|
* @param LoggerInterface $logger
|
2016-11-29 00:31:16 +01:00
|
|
|
*/
|
2017-03-09 23:20:58 +01:00
|
|
|
public function setLogger(LoggerInterface $logger)
|
2016-11-29 00:31:16 +01:00
|
|
|
{
|
|
|
|
$this->logger = $logger;
|
|
|
|
}
|
2015-07-24 00:53:41 +02:00
|
|
|
|
2017-03-09 23:20:58 +01:00
|
|
|
public function start()
|
2016-11-29 00:31:16 +01:00
|
|
|
{
|
|
|
|
if (!$this->logger) {
|
|
|
|
throw new \InvalidArgumentException("No Logger property passed to MonologErrorHandler."
|
|
|
|
. "Is your Injector config correct?");
|
|
|
|
}
|
2015-07-24 00:53:41 +02:00
|
|
|
|
2016-11-29 00:31:16 +01:00
|
|
|
ErrorHandler::register($this->logger);
|
|
|
|
}
|
2015-07-24 00:53:41 +02:00
|
|
|
}
|