silverstripe-framework/src/Logging/MonologErrorHandler.php

38 lines
752 B
PHP
Raw Normal View History

<?php
namespace SilverStripe\Logging;
use Psr\Log\LoggerInterface;
use Monolog\ErrorHandler;
/**
* Simple adaptor to start Monolog\ErrorHandler
*/
class MonologErrorHandler
{
/**
* @var LoggerInterface
*/
2016-11-29 00:31:16 +01:00
private $logger;
2016-11-29 00:31:16 +01:00
/**
* Set the PSR-3 logger to send errors & exceptions to
*
* @param LoggerInterface $logger
2016-11-29 00:31:16 +01:00
*/
public function setLogger(LoggerInterface $logger)
2016-11-29 00:31:16 +01:00
{
$this->logger = $logger;
}
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?");
}
2016-11-29 00:31:16 +01:00
ErrorHandler::register($this->logger);
}
}