Skip to content

Commit

Permalink
Deprecate several Log methods.
Browse files Browse the repository at this point in the history
Having both loaded/enabled modes makes Log more complex than it needs to
be. There are very few cases where you need to disable/enable loggers.
These can generally be solved by droping loggers.
  • Loading branch information
markstory committed Aug 13, 2013
1 parent 88f2f30 commit a8a6513
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 64 deletions.
54 changes: 21 additions & 33 deletions lib/Cake/Log/Log.php
Expand Up @@ -192,18 +192,6 @@ public static function reset() {
static::$_registry = null;
}

/**
* @deprecated Use Configure::write() to configure logging.
* @see App/Config/logging.php
* @return void
*/
public static function config($key, $config) {
trigger_error(
__d('cake_dev', 'You must use Configure::write() to define logging configuration. Or use engine() to inject new adapter.'),
E_USER_WARNING
);
}

/**
* Returns the keynames of the currently active streams
*
Expand All @@ -226,6 +214,18 @@ public static function levels() {
return static::$_levels;
}

/**
* @deprecated Use Configure::write() to configure logging.
* @see App/Config/logging.php
* @return void
*/
public static function config($key, $config) {
trigger_error(
__d('cake_dev', 'You must use Configure::write() to define logging configuration. Or use engine() to inject new adapter.'),
E_USER_WARNING
);
}

/**
* Removes a stream from the active streams. Once a stream has been removed
* it will no longer have messages sent to it.
Expand All @@ -239,51 +239,39 @@ public static function drop($streamName) {
}

/**
* Checks wether $streamName is enabled
* Checks whether $streamName is enabled
*
* @param string $streamName to check
* @return bool
* @throws Cake\Error\Exception
* @deprecated This method will be removed in 3.0 stable.
*/
public static function enabled($streamName) {
static::_init();
if (!isset(static::$_registry->{$streamName})) {
throw new Error\Exception(__d('cake_dev', 'Stream %s not found', $streamName));
}
return static::$_registry->enabled($streamName);
throw new Error\Exception(__d('cake_dev', 'Log::enabled() is deprecated. Use Log::configured() instead.'));
}

/**
* Enable stream. Streams that were previously disabled
* can be re-enabled with this method.
* Enable stream.
*
* @param string $streamName to enable
* @return void
* @throws Cake\Error\Exception
* @deprecated This method will be removed in 3.0 stable.
*/
public static function enable($streamName) {
static::_init();
if (!isset(static::$_registry->{$streamName})) {
throw new Error\Exception(__d('cake_dev', 'Stream %s not found', $streamName));
}
static::$_registry->enable($streamName);
throw new Error\Exception(__d('cake_dev', 'Log::enable() is deprecated. Use Log::engine() instead.'));
}

/**
* Disable stream. Disabling a stream will
* prevent that log stream from receiving any messages until
* its re-enabled.
* Disable stream.
*
* @param string $streamName to disable
* @return void
* @throws Cake\Error\Exception
* @deprecated This method will be removed in 3.0 stable.
*/
public static function disable($streamName) {
static::_init();
if (!isset(static::$_registry->{$streamName})) {
throw new Error\Exception(__d('cake_dev', 'Stream %s not found', $streamName));
}
static::$_registry->disable($streamName);
throw new Error\Exception(__d('cake_dev', 'Log::disable() is deprecated. Use Log::drop() instead.'));
}

/**
Expand Down
39 changes: 8 additions & 31 deletions lib/Cake/Test/TestCase/Log/LogTest.php
Expand Up @@ -217,53 +217,30 @@ public function testSelectiveLoggingByLevel() {
}

/**
* test enable
* test enable() throws exceptions
*
* @expectedException Cake\Error\Exception
*/
public function testStreamEnable() {
Configure::write('Log.spam', array(
'engine' => 'File',
'file' => 'spam',
));
$this->assertTrue(Log::enabled('spam'));
Log::drop('spam');
Log::enable('bogus_stream');
}

/**
* test disable
*
* @expectedException Cake\Error\Exception
*/
public function testStreamDisable() {
Configure::write('Log.spam', array(
'engine' => 'File',
'file' => 'spam',
));
$this->assertTrue(Log::enabled('spam'));
Log::disable('spam');
$this->assertFalse(Log::enabled('spam'));
Log::drop('spam');
Log::enable('bogus_stream');
Log::enable('debug');
}

/**
* test enabled() invalid stream
* test enabled() throws exceptions
*
* @expectedException Cake\Error\Exception
*/
public function testStreamEnabledInvalid() {
Log::enabled('bogus_stream');
public function testStreamEnabled() {
Log::enabled('debug');
}

/**
* test disable invalid stream
* test disable() throws exceptions
*
* @expectedException Cake\Error\Exception
*/
public function testStreamDisableInvalid() {
Log::disable('bogus_stream');
public function testStreamDisable() {
Log::disable('debug');
}

protected function _resetLogConfig() {
Expand Down

0 comments on commit a8a6513

Please sign in to comment.