Skip to content

Commit

Permalink
Change types -> levels as its a confusing naming alias.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Oct 7, 2012
1 parent 4941bbf commit 44714fe
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 38 deletions.
47 changes: 35 additions & 12 deletions lib/Cake/Log/Engine/BaseLog.php
Expand Up @@ -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'] : [];
}

}
13 changes: 5 additions & 8 deletions lib/Cake/Log/Engine/FileLog.php
@@ -1,9 +1,5 @@
<?php
/**
* File Storage stream for Logging
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
Expand All @@ -16,14 +12,14 @@
* @since CakePHP(tm) v 1.3
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

namespace Cake\Log\Engine;

use Cake\Log\Engine\BaseLog;
use Cake\Utility\Hash;

/**
* File Storage stream for Logging. Writes logs to different files
* based on the type of log it is.
* based on the level of log it is.
*
* @package Cake.Log.Engine
*/
Expand All @@ -48,7 +44,7 @@ class FileLog extends BaseLog {
*
* Config
*
* - `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
* - `file` log file name
* - `path` the path to save logs on.
Expand All @@ -60,10 +56,11 @@ public function __construct($config = array()) {
$config = Hash::merge(array(
'path' => 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)) {
Expand Down
10 changes: 2 additions & 8 deletions lib/Cake/Log/Log.php
Expand Up @@ -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
Expand Down Expand Up @@ -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) ||
Expand Down
9 changes: 4 additions & 5 deletions lib/Cake/Test/TestApp/Log/Engine/TestAppLog.php
@@ -1,9 +1,5 @@
<?php
/**
* Test Suite Test App Logging stream class.
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
Expand All @@ -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) {
Expand Down
@@ -1,9 +1,5 @@
<?php
/**
* Test Suite Test Plugin Logging stream class.
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
Expand All @@ -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) {
Expand Down

0 comments on commit 44714fe

Please sign in to comment.