mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
NEW Add getLogger() to MonologErrorHandler and add test for exception without one
This commit is contained in:
parent
5bd05a2deb
commit
3cdb73bd44
@ -16,19 +16,31 @@ class MonologErrorHandler implements ErrorHandler
|
||||
* Set the PSR-3 logger to send errors & exceptions to
|
||||
*
|
||||
* @param LoggerInterface $logger
|
||||
* @return $this
|
||||
*/
|
||||
public function setLogger(LoggerInterface $logger)
|
||||
{
|
||||
$this->logger = $logger;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the PSR-3 logger to send errors & exceptions to
|
||||
*
|
||||
* @return LoggerInterface
|
||||
*/
|
||||
public function getLogger()
|
||||
{
|
||||
return $this->logger;
|
||||
}
|
||||
|
||||
public function start()
|
||||
{
|
||||
if (!$this->logger) {
|
||||
if (!$this->getLogger()) {
|
||||
throw new \InvalidArgumentException("No Logger property passed to MonologErrorHandler."
|
||||
. "Is your Injector config correct?");
|
||||
}
|
||||
|
||||
MonologHandler::register($this->logger);
|
||||
MonologHandler::register($this->getLogger());
|
||||
}
|
||||
}
|
||||
|
19
tests/php/Logging/MonologErrorHandlerTest.php
Normal file
19
tests/php/Logging/MonologErrorHandlerTest.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Logging\Tests;
|
||||
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\Logging\MonologErrorHandler;
|
||||
|
||||
class MonologErrorHandlerTest extends SapphireTest
|
||||
{
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessageRegExp /No Logger property passed to MonologErrorHandler/
|
||||
*/
|
||||
public function testStartThrowsExceptionWithoutLoggerDefined()
|
||||
{
|
||||
$handler = new MonologErrorHandler();
|
||||
$handler->start();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user