Skip to content
Permalink
Browse files

Update Log to use StaticConfigTrait.

Update Log to use the new trait. This simplifies some of the internals
of Log as _init() is not called quite as often but still gives the same
results as before.
  • Loading branch information...
markstory committed Aug 26, 2013
1 parent 42ee554 commit cdc68187275d34956e6dddabdbb09ea6835e09a3
Showing with 8 additions and 49 deletions.
  1. +8 −46 lib/Cake/Log/Log.php
  2. +0 −3 lib/Cake/Test/TestCase/Log/LogTest.php
@@ -13,6 +13,7 @@
*/
namespace Cake\Log;
use Cake\Core\StaticConfigTrait;
use Cake\Error;
use Cake\Log\Engine\BaseLog;
@@ -103,6 +104,10 @@
*/
class Log {
use StaticConfigTrait {
config as protected _config;
}
/**
* Internal flag for tracking whether or not configuration has been changed.
*
@@ -203,16 +208,6 @@ public static function reset() {
static::$_dirtyConfig = true;
}
/**
* Returns the keynames of the currently active streams
*
* @return array Array of configured log streams.
*/
public static function configured() {
static::_init();
return static::$_registry->loaded();
}
/**
* Gets log levels
*
@@ -263,44 +258,11 @@ public static function levels() {
* @see App/Config/logging.php
*/
public static function config($key, $config = null) {
// Read config.
if ($config === null && is_string($key)) {
return isset(static::$_config[$key]) ? static::$_config[$key] : null;
}
if ($config === null && is_array($key)) {
foreach ($key as $name => $settings) {
static::config($name, $settings);
}
return;
}
if (isset(static::$_config[$key])) {
throw new Error\Exception(__d('cake_dev', 'Cannot reconfigure existing adapter "%s"', $key));
$return = static::_config($key, $config);
if ($return !== null) {
return $return;
}
static::$_dirtyConfig = true;
if (is_object($config)) {
$config = ['className' => $config];
}
if (isset($config['engine']) && empty($config['className'])) {
$config['className'] = $config['engine'];
unset($config['engine']);
}
static::$_config[$key] = $config;
}
/**
* Removes a stream from the active streams.
*
* Once a stream has been removed it will no longer have messages sent to it.
* The original configuration data will also be removed. You can use this method
* when reconfiguring a logger or when you want to remove a logger.
*
* @param string $streamName Key name of a configured logger to remove.
* @return void
*/
public static function drop($streamName) {
static::_init();
static::$_registry->unload($streamName);
unset(static::$_config[$streamName]);
}
/**
@@ -136,9 +136,6 @@ public static function configProvider() {
'path' => TMP . 'tests',
]],
'Direct instance' => [new FileLog()],
'Closure factory' => [function () {
return new FileLog();
}],
];
}

0 comments on commit cdc6818

Please sign in to comment.
You can’t perform that action at this time.