Browse Source

Update exception in log classes.

ADmad 11 years ago
parent
commit
d1610d97dc
4 changed files with 17 additions and 17 deletions
  1. 3 2
      src/Log/Engine/ConsoleLog.php
  2. 4 4
      src/Log/Log.php
  3. 5 6
      src/Log/LogEngineRegistry.php
  4. 5 5
      tests/TestCase/Log/LogTest.php

+ 3 - 2
src/Log/Engine/ConsoleLog.php

@@ -16,6 +16,7 @@ namespace Cake\Log\Engine;
 
 use Cake\Console\ConsoleOutput;
 use Cake\Core\Exception\Exception;
+use \InvalidArgumentException;
 
 /**
  * Console logging. Writes logs to console output.
@@ -52,7 +53,7 @@ class ConsoleLog extends BaseLog {
  * - `outputAs` integer or ConsoleOutput::[RAW|PLAIN|COLOR]
  *
  * @param array $config Options for the FileLog, see above.
- * @throws \Cake\Core\Exception\Exception
+ * @throws \InvalidArgumentException
  */
 	public function __construct(array $config = array()) {
 		if (DS === '\\' && !(bool)env('ANSICON')) {
@@ -69,7 +70,7 @@ class ConsoleLog extends BaseLog {
 		} elseif (is_string($config['stream'])) {
 			$this->_output = new ConsoleOutput($config['stream']);
 		} else {
-			throw new Exception('`stream` not a ConsoleOutput nor string');
+			throw new InvalidArgumentException('`stream` not a ConsoleOutput nor string');
 		}
 		$this->_output->outputAs($config['outputAs']);
 	}

+ 4 - 4
src/Log/Log.php

@@ -14,8 +14,8 @@
 namespace Cake\Log;
 
 use Cake\Core\StaticConfigTrait;
-use Cake\Core\Exception\Exception;
 use Cake\Log\Engine\BaseLog;
+use InvalidArgumentException;
 
 /**
  * Logs messages to configured Log adapters.  One or more adapters
@@ -246,7 +246,7 @@ class Log {
  * @param string|array $key The name of the logger config, or an array of multiple configs.
  * @param array $config An array of name => config data for adapter.
  * @return mixed null when adding configuration and an array of configuration data when reading.
- * @throws \Cake\Core\Exception\Exception When trying to modify an existing config.
+ * @throws \BadMethodCallException When trying to modify an existing config.
  */
 	public static function config($key, $config = null) {
 		$return = static::_config($key, $config);
@@ -316,7 +316,7 @@ class Log {
  * @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 bool Success
- * @throws \Cake\Core\Exception\Exception If invalid level is passed.
+ * @throws \InvalidArgumentException If invalid level is passed.
  */
 	public static function write($level, $message, $scope = array()) {
 		static::_init();
@@ -325,7 +325,7 @@ class Log {
 		}
 
 		if (!in_array($level, static::$_levels)) {
-			throw new Exception(sprintf('Invalid log level "%s"', $level));
+			throw new InvalidArgumentException(sprintf('Invalid log level "%s"', $level));
 		}
 
 		$logged = false;

+ 5 - 6
src/Log/LogEngineRegistry.php

@@ -15,9 +15,9 @@
 namespace Cake\Log;
 
 use Cake\Core\App;
-use Cake\Core\Exception\Exception;
 use Cake\Core\ObjectRegistry;
 use Cake\Log\LogInterface;
+use \RuntimeException;
 
 /**
  * Registry of loaded log engines
@@ -48,10 +48,10 @@ class LogEngineRegistry extends ObjectRegistry {
  * @param string $class The classname that is missing.
  * @param string $plugin The plugin the logger is missing in.
  * @return void
- * @throws \Cake\Core\Exception\Exception
+ * @throws \RuntimeException
  */
 	protected function _throwMissingClassError($class, $plugin) {
-		throw new Exception(sprintf('Could not load class %s', $class));
+		throw new RuntimeException(sprintf('Could not load class %s', $class));
 	}
 
 /**
@@ -63,8 +63,7 @@ class LogEngineRegistry extends ObjectRegistry {
  * @param string $alias The alias of the object.
  * @param array $settings An array of settings to use for the logger.
  * @return \Cake\Log\LogInterface The constructed logger class.
- * @throws \Cake\Core\Exception\Exception when an object doesn't implement
- *    the correct interface.
+ * @throws \RuntimeException when an object doesn't implement the correct interface.
  */
 	protected function _create($class, $alias, $settings) {
 		if (is_object($class)) {
@@ -79,7 +78,7 @@ class LogEngineRegistry extends ObjectRegistry {
 			return $instance;
 		}
 
-		throw new Exception(
+		throw new RuntimeException(
 			'Loggers must implement Cake\Log\LogInterface.'
 		);
 	}

+ 5 - 5
tests/TestCase/Log/LogTest.php

@@ -69,7 +69,7 @@ class LogTest extends TestCase {
 /**
  * test all the errors from failed logger imports
  *
- * @expectedException \Cake\Core\Exception\Exception
+ * @expectedException RuntimeException
  * @return void
  */
 	public function testImportingLoggerFailure() {
@@ -91,7 +91,7 @@ class LogTest extends TestCase {
 /**
  * test that loggers have to implement the correct interface.
  *
- * @expectedException \Cake\Core\Exception\Exception
+ * @expectedException \RuntimeException
  * @return void
  */
 	public function testNotImplementingInterface() {
@@ -122,7 +122,7 @@ class LogTest extends TestCase {
 /**
  * test config() with valid key name
  *
- * @expectedException \Cake\Core\Exception\Exception
+ * @expectedException \InvalidArgumentException
  * @return void
  */
 	public function testInvalidLevel() {
@@ -166,7 +166,7 @@ class LogTest extends TestCase {
  * Test that config() throws an exception when adding an
  * adapter with the wrong type.
  *
- * @expectedException \Cake\Core\Exception\Exception
+ * @expectedException \RuntimeException
  * @return void
  */
 	public function testConfigInjectErrorOnWrongType() {
@@ -195,7 +195,7 @@ class LogTest extends TestCase {
 /**
  * Ensure you cannot reconfigure a log adapter.
  *
- * @expectedException BadMethodCallException
+ * @expectedException \BadMethodCallException
  * @return void
  */
 	public function testConfigErrorOnReconfigure() {