Permalink
Browse files

Throw exception for invalid log level.

  • Loading branch information...
ADmad committed Dec 10, 2013
1 parent 932b221 commit 91b1db37740017e0c8480bfc639378a4e222cfc3
Showing with 17 additions and 0 deletions.
  1. +6 −0 Cake/Log/Log.php
  2. +11 −0 Cake/Test/TestCase/Log/LogTest.php
View
@@ -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};
@@ -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.
*

0 comments on commit 91b1db3

Please sign in to comment.