mirror of
https://github.com/Seldaek/monolog.git
synced 2025-07-31 10:20:14 +02:00
Throw an exception on invalid level name
This commit is contained in:
@@ -322,6 +322,10 @@ class Logger
|
||||
*/
|
||||
public static function getLevelName($level)
|
||||
{
|
||||
if (!isset(static::$levels[$level])) {
|
||||
throw new \InvalidArgumentException('Level "'.$level.'" is not defined, use one of: '.implode(', ', array_keys(static::$levels)));
|
||||
}
|
||||
|
||||
return static::$levels[$level];
|
||||
}
|
||||
|
||||
|
@@ -25,6 +25,23 @@ class LoggerTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals('foo', $logger->getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Monolog\Logger::getLevelName
|
||||
*/
|
||||
public function testGetLevelName()
|
||||
{
|
||||
$this->assertEquals('ERROR', Logger::getLevelName(Logger::ERROR));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Monolog\Logger::getLevelName
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
public function testGetLevelNameThrows()
|
||||
{
|
||||
Logger::getLevelName(5);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Monolog\Logger::__construct
|
||||
*/
|
||||
|
Reference in New Issue
Block a user