diff --git a/lib/Cake/Log/Engine/BaseLog.php b/lib/Cake/Log/Engine/BaseLog.php index fb66e4ec271..e4a34e5418c 100644 --- a/lib/Cake/Log/Engine/BaseLog.php +++ b/lib/Cake/Log/Engine/BaseLog.php @@ -27,36 +27,59 @@ abstract class BaseLog implements LogInterface { * * @var string */ - protected $_config = array(); + protected $_config = []; /** * __construct method * * @return void */ - public function __construct($config = array()) { + public function __construct(array $config = []) { $this->config($config); } /** * Sets instance config. When $config is null, returns config array * - * Config + * ### Options * - * - `types` string or array, levels the engine is interested in + * - `levels` string or array, levels the engine is interested in * - `scopes` string or array, scopes the engine is interested in * - * @param array $config engine configuration - * @return array + * @param array|null $config Either an array of configuration, or null to get + * current configuration. + * @return array Array of configuration options. */ - public function config($config = array()) { - if (!empty($config)) { - if (isset($config['types']) && is_string($config['types'])) { - $config['types'] = array($config['types']); - } - $this->_config = $config; + public function config($config = null) { + if (empty($config)) { + return $this->_config; + } + $config += ['levels' => [], 'scopes' => []]; + $config['scopes'] = (array)$config['scopes']; + $config['levels'] = (array)$config['levels']; + if (isset($config['types']) && empty($config['levels'])) { + $config['levels'] = $config['types']; } + $this->_config = $config; return $this->_config; } +/** + * Get the levls this logger is interested in. + * + * @return array + */ + public function levels() { + return isset($this->_config['levels']) ? $this->_config['levels'] : []; + } + +/** + * Get the scopes this logger is interested in. + * + * @return array + */ + public function scopes() { + return isset($this->_config['scopes']) ? $this->_config['scopes'] : []; + } + } diff --git a/lib/Cake/Log/Engine/FileLog.php b/lib/Cake/Log/Engine/FileLog.php index 5a632fec3aa..e283083002e 100644 --- a/lib/Cake/Log/Engine/FileLog.php +++ b/lib/Cake/Log/Engine/FileLog.php @@ -1,9 +1,5 @@ LOGS, 'file' => null, - 'types' => null, + 'levels' => null, 'scopes' => array(), ), $this->_config); $config = $this->config($config); + $this->_path = $config['path']; $this->_file = $config['file']; if (!empty($this->_file) && !preg_match('/\.log$/', $this->_file)) { diff --git a/lib/Cake/Log/Log.php b/lib/Cake/Log/Log.php index 3721297d64c..9b109660d8c 100644 --- a/lib/Cake/Log/Log.php +++ b/lib/Cake/Log/Log.php @@ -17,7 +17,6 @@ use Cake\Core\Configure; use Cake\Error; use Cake\Log\Engine\BaseLog; -use Cake\Log\Engine\FileLog; /** * Logs messages to configured Log adapters. One or more adapters @@ -363,13 +362,8 @@ public static function write($level, $message, $scope = array()) { $logger = static::$_Collection->{$streamName}; $levels = $scopes = null; if ($logger instanceof BaseLog) { - $config = $logger->config(); - if (isset($config['types'])) { - $levels = $config['types']; - } - if (isset($config['scopes'])) { - $scopes = $config['scopes']; - } + $levels = $logger->levels(); + $scopes = $logger->scopes(); } $correctLevel = ( empty($levels) || diff --git a/lib/Cake/Test/TestApp/Log/Engine/TestAppLog.php b/lib/Cake/Test/TestApp/Log/Engine/TestAppLog.php index 521184ec56f..11c86d32e73 100644 --- a/lib/Cake/Test/TestApp/Log/Engine/TestAppLog.php +++ b/lib/Cake/Test/TestApp/Log/Engine/TestAppLog.php @@ -1,9 +1,5 @@ * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) * @@ -17,9 +13,12 @@ * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ namespace TestApp\Log\Engine; -use Cake\Log\LogInterface; + use Cake\Log\Engine\BaseLog; +/** + * Test Suite Test App Logging stream class. + */ class TestAppLog extends BaseLog { public function write($type, $message) { diff --git a/lib/Cake/Test/TestApp/Plugin/TestPlugin/Log/Engine/TestPluginLog.php b/lib/Cake/Test/TestApp/Plugin/TestPlugin/Log/Engine/TestPluginLog.php index f3b905b9663..c07090da268 100644 --- a/lib/Cake/Test/TestApp/Plugin/TestPlugin/Log/Engine/TestPluginLog.php +++ b/lib/Cake/Test/TestApp/Plugin/TestPlugin/Log/Engine/TestPluginLog.php @@ -1,9 +1,5 @@ * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) * @@ -16,10 +12,13 @@ * @since CakePHP(tm) v 1.3 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ - namespace TestPlugin\Log\Engine; + use Cake\Log\LogInterface; +/** + * Test Suite Test Plugin Logging stream class. + */ class TestPluginLog implements LogInterface { public function write($type, $message) {