Skip to content

Commit

Permalink
Update exception in log classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Aug 31, 2014
1 parent 63a215b commit d1610d9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
5 changes: 3 additions & 2 deletions src/Log/Engine/ConsoleLog.php
Expand Up @@ -16,6 +16,7 @@

use Cake\Console\ConsoleOutput;
use Cake\Core\Exception\Exception;
use \InvalidArgumentException;

/**
* Console logging. Writes logs to console output.
Expand Down Expand Up @@ -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')) {
Expand All @@ -69,7 +70,7 @@ public function __construct(array $config = array()) {
} 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']);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Log/Log.php
Expand Up @@ -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
Expand Down Expand Up @@ -246,7 +246,7 @@ public static function levels() {
* @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);
Expand Down Expand Up @@ -316,7 +316,7 @@ 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 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();
Expand All @@ -325,7 +325,7 @@ public static function write($level, $message, $scope = array()) {
}

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;
Expand Down
11 changes: 5 additions & 6 deletions src/Log/LogEngineRegistry.php
Expand Up @@ -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
Expand Down Expand Up @@ -48,10 +48,10 @@ protected function _resolveClassName($class) {
* @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));
}

/**
Expand All @@ -63,8 +63,7 @@ protected function _throwMissingClassError($class, $plugin) {
* @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)) {
Expand All @@ -79,7 +78,7 @@ protected function _create($class, $alias, $settings) {
return $instance;
}

throw new Exception(
throw new RuntimeException(
'Loggers must implement Cake\Log\LogInterface.'
);
}
Expand Down
10 changes: 5 additions & 5 deletions tests/TestCase/Log/LogTest.php
Expand Up @@ -69,7 +69,7 @@ public function testImportingLoggers() {
/**
* test all the errors from failed logger imports
*
* @expectedException \Cake\Core\Exception\Exception
* @expectedException RuntimeException
* @return void
*/
public function testImportingLoggerFailure() {
Expand All @@ -91,7 +91,7 @@ public function testValidKeyName() {
/**
* test that loggers have to implement the correct interface.
*
* @expectedException \Cake\Core\Exception\Exception
* @expectedException \RuntimeException
* @return void
*/
public function testNotImplementingInterface() {
Expand Down Expand Up @@ -122,7 +122,7 @@ public function testDrop() {
/**
* test config() with valid key name
*
* @expectedException \Cake\Core\Exception\Exception
* @expectedException \InvalidArgumentException
* @return void
*/
public function testInvalidLevel() {
Expand Down Expand Up @@ -166,7 +166,7 @@ public function testConfigVariants($settings) {
* 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() {
Expand Down Expand Up @@ -195,7 +195,7 @@ public function testConfigRead() {
/**
* Ensure you cannot reconfigure a log adapter.
*
* @expectedException BadMethodCallException
* @expectedException \BadMethodCallException
* @return void
*/
public function testConfigErrorOnReconfigure() {
Expand Down

0 comments on commit d1610d9

Please sign in to comment.