1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-12 08:04:02 +02:00

Add support for PSR-3 levels to all public APIs accepting levels, fixes #421

This commit is contained in:
Jordi Boggiano
2014-09-30 13:59:45 +01:00
parent 43ca6dc06b
commit feb19af2d4
13 changed files with 91 additions and 15 deletions

View File

@@ -62,6 +62,17 @@ class AbstractHandlerTest extends TestCase
$this->assertFalse($handler->isHandling($this->getRecord(Logger::DEBUG)));
}
/**
* @covers Monolog\Handler\AbstractHandler::__construct
*/
public function testHandlesPsrStyleLevels()
{
$handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractHandler', array('warning', false));
$this->assertFalse($handler->isHandling($this->getRecord(Logger::DEBUG)));
$handler->setLevel('debug');
$this->assertTrue($handler->isHandling($this->getRecord(Logger::DEBUG)));
}
/**
* @covers Monolog\Handler\AbstractHandler::getFormatter
* @covers Monolog\Handler\AbstractHandler::getDefaultFormatter

View File

@@ -80,6 +80,16 @@ class FilterHandlerTest extends TestCase
$levels = array(Logger::INFO, Logger::ERROR);
$handler->setAcceptedLevels($levels);
$this->assertSame($levels, $handler->getAcceptedLevels());
$handler->setAcceptedLevels(array('info', 'error'));
$this->assertSame($levels, $handler->getAcceptedLevels());
$levels = array(Logger::CRITICAL, Logger::ALERT, Logger::EMERGENCY);
$handler->setAcceptedLevels(Logger::CRITICAL, Logger::EMERGENCY);
$this->assertSame($levels, $handler->getAcceptedLevels());
$handler->setAcceptedLevels('critical', 'emergency');
$this->assertSame($levels, $handler->getAcceptedLevels());
}
/**

View File

@@ -156,6 +156,22 @@ class FingersCrossedHandlerTest extends TestCase
$this->assertTrue($test->hasWarningRecords());
}
/**
* @covers Monolog\Handler\FingersCrossedHandler::__construct
* @covers Monolog\Handler\FingersCrossed\ErrorLevelActivationStrategy::__construct
* @covers Monolog\Handler\FingersCrossed\ErrorLevelActivationStrategy::isHandlerActivated
*/
public function testErrorLevelActivationStrategyWithPsrLevel()
{
$test = new TestHandler();
$handler = new FingersCrossedHandler($test, new ErrorLevelActivationStrategy('warning'));
$handler->handle($this->getRecord(Logger::DEBUG));
$this->assertFalse($test->hasDebugRecords());
$handler->handle($this->getRecord(Logger::WARNING));
$this->assertTrue($test->hasDebugRecords());
$this->assertTrue($test->hasWarningRecords());
}
/**
* @covers Monolog\Handler\FingersCrossed\ChannelLevelActivationStrategy::__construct
* @covers Monolog\Handler\FingersCrossed\ChannelLevelActivationStrategy::isHandlerActivated
@@ -173,6 +189,23 @@ class FingersCrossedHandlerTest extends TestCase
$this->assertTrue($test->hasWarningRecords());
}
/**
* @covers Monolog\Handler\FingersCrossed\ChannelLevelActivationStrategy::__construct
* @covers Monolog\Handler\FingersCrossed\ChannelLevelActivationStrategy::isHandlerActivated
*/
public function testChannelLevelActivationStrategyWithPsrLevels()
{
$test = new TestHandler();
$handler = new FingersCrossedHandler($test, new ChannelLevelActivationStrategy('error', array('othertest' => 'debug')));
$handler->handle($this->getRecord(Logger::WARNING));
$this->assertFalse($test->hasWarningRecords());
$record = $this->getRecord(Logger::DEBUG);
$record['channel'] = 'othertest';
$handler->handle($record);
$this->assertTrue($test->hasDebugRecords());
$this->assertTrue($test->hasWarningRecords());
}
/**
* @covers Monolog\Handler\FingersCrossedHandler::handle
*/

View File

@@ -13,7 +13,6 @@ namespace Monolog\Handler;
use Monolog\TestCase;
use Monolog\Logger;
use Psr\Log\LogLevel;
class NewRelicHandlerTest extends TestCase
{
@@ -85,7 +84,7 @@ class NewRelicHandlerTest extends TestCase
public function testTheAppNameCanBeInjectedFromtheConstructor()
{
$handler = new StubNewRelicHandler(LogLevel::ALERT, false, 'myAppName');
$handler = new StubNewRelicHandler(Logger::DEBUG, false, 'myAppName');
$handler->handle($this->getRecord(Logger::ERROR, 'log message'));
$this->assertEquals('myAppName', self::$appname);
@@ -93,7 +92,7 @@ class NewRelicHandlerTest extends TestCase
public function testTheAppNameCanBeOverriddenFromEachLog()
{
$handler = new StubNewRelicHandler(LogLevel::ALERT, false, 'myAppName');
$handler = new StubNewRelicHandler(Logger::DEBUG, false, 'myAppName');
$handler->handle($this->getRecord(Logger::ERROR, 'log message', array('appname' => 'logAppName')));
$this->assertEquals('logAppName', self::$appname);