Skip to content

Commit

Permalink
Throw exception for invalid log level.
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Dec 10, 2013
1 parent 932b221 commit 91b1db3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Cake/Log/Log.php
Expand Up @@ -325,12 +325,18 @@ public static function engine($name) {
* @param string|array $scope The scope(s) a log message is being created in.
* See Cake\Log\Log::config() for more information on logging scopes.
* @return boolean Success
* @throws Cake\Error\Exception If invalid level is passed.
*/
public static function write($level, $message, $scope = array()) {
static::_init();
if (is_int($level) && isset(static::$_levels[$level])) {
$level = static::$_levels[$level];
}

if (!in_array($level, static::$_levels)) {
throw new Error\Exception(__d('cake_dev', 'Invalid log level "%s"', $level));
}

$logged = false;
foreach (static::$_registry->loaded() as $streamName) {
$logger = static::$_registry->{$streamName};
Expand Down
11 changes: 11 additions & 0 deletions Cake/Test/TestCase/Log/LogTest.php
Expand Up @@ -114,6 +114,17 @@ public function testDrop() {
$this->assertNotContains('file', $result);
}

/**
* test config() with valid key name
*
* @expectedException Cake\Error\Exception
* @return void
*/
public function testInvalidLevel() {
Log::config('myengine', array('engine' => 'File'));
Log::write('invalid', 'This will not be logged');
}

/**
* Provider for config() tests.
*
Expand Down

0 comments on commit 91b1db3

Please sign in to comment.