minor updates to the logging changeset

- change usage of Set to Hash
- updating bootstrap.php
- adding docblocks
- avoid silencing unlink errors in tests
This commit is contained in:
Rachman Chavik 2012-05-11 16:15:15 +07:00
parent 912a5f6d12
commit e5b33627d5
7 changed files with 47 additions and 34 deletions

View file

@ -155,6 +155,7 @@ Configure::write('Dispatcher.filters', array(
/** /**
* Configures default file logging options * Configures default file logging options
*/ */
App::uses('CakeLog', 'Log');
CakeLog::config('debug', array( CakeLog::config('debug', array(
'engine' => 'FileLog', 'engine' => 'FileLog',
'types' => array('notice', 'info', 'debug'), 'types' => array('notice', 'info', 'debug'),

View file

@ -95,6 +95,7 @@ Configure::write('Dispatcher.filters', array(
/** /**
* Configures default file logging options * Configures default file logging options
*/ */
App::uses('CakeLog', 'Log');
CakeLog::config('debug', array( CakeLog::config('debug', array(
'engine' => 'FileLog', 'engine' => 'FileLog',
'scopes' => array('notice', 'info', 'debug'), 'scopes' => array('notice', 'info', 'debug'),

View file

@ -219,9 +219,6 @@ class CakeLog {
* @return void * @return void
*/ */
protected static function _autoConfig() { protected static function _autoConfig() {
if (empty(self::$_Collection)) {
self::_init();
}
self::$_Collection->load('error', array( self::$_Collection->load('error', array(
'engine' => 'FileLog', 'engine' => 'FileLog',
'types' => array('error', 'warning'), 'types' => array('error', 'warning'),
@ -275,14 +272,18 @@ class CakeLog {
if (is_string($type) && empty($scope) && !in_array($type, $levels)) { if (is_string($type) && empty($scope) && !in_array($type, $levels)) {
$scope = $type; $scope = $type;
} }
if (empty(self::$_streams)) { if (!self::$_Collection->attached()) {
self::_autoConfig(); self::_autoConfig();
} }
foreach (self::$_Collection->enabled() as $streamName) { foreach (self::$_Collection->enabled() as $streamName) {
$logger = self::$_Collection->{$streamName}; $logger = self::$_Collection->{$streamName};
$types = null;
$scopes = array();
if ($logger instanceof BaseLog) {
$config = $logger->config(); $config = $logger->config();
$types = $config['types']; $types = $config['types'];
$scopes = $config['scopes']; $scopes = $config['scopes'];
}
if (is_string($scope)) { if (is_string($scope)) {
$inScope = in_array($scope, $scopes); $inScope = in_array($scope, $scopes);
} else { } else {

View file

@ -45,6 +45,11 @@ abstract class BaseLog implements CakeLogInterface {
/** /**
* Sets instance config. When $config is null, returns config array * Sets instance config. When $config is null, returns config array
* *
* Config
*
* - `types` string or array, levels the engine is interested in
* - `scopes` string or array, scopes the engine is interested in
*
* @param array $config engine configuration * @param array $config engine configuration
* @return array * @return array
*/ */

View file

@ -39,6 +39,8 @@ class ConsoleLog extends BaseLog {
* *
* Config * Config
* *
* - `types` string or array, levels the engine is interested in
* - `scopes` string or array, scopes the engine is interested in
* - `stream` the path to save logs on. * - `stream` the path to save logs on.
* - `outputAs` integer or ConsoleOutput::[RAW|PLAIN|COLOR] * - `outputAs` integer or ConsoleOutput::[RAW|PLAIN|COLOR]
* *
@ -47,7 +49,7 @@ class ConsoleLog extends BaseLog {
*/ */
public function __construct($config = array()) { public function __construct($config = array()) {
parent::__construct($config); parent::__construct($config);
$config = Set::merge(array( $config = Hash::merge(array(
'stream' => 'php://stderr', 'stream' => 'php://stderr',
'types' => null, 'types' => null,
'scopes' => array(), 'scopes' => array(),

View file

@ -39,13 +39,16 @@ class FileLog extends BaseLog {
* *
* Config * Config
* *
* - `types` 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. * - `path` the path to save logs on.
* *
* @param array $options Options for the FileLog, see above. * @param array $options Options for the FileLog, see above.
*/ */
public function __construct($config = array()) { public function __construct($config = array()) {
parent::__construct($config); parent::__construct($config);
$config = Set::merge(array( $config = Hash::merge(array(
'path' => LOGS, 'path' => LOGS,
'file' => null, 'file' => null,
'types' => null, 'types' => null,

View file

@ -281,10 +281,29 @@ class CakeLogTest extends CakeTestCase {
CakeLog::disable('bogus_stream'); CakeLog::disable('bogus_stream');
} }
protected function _resetLogConfig() {
CakeLog::config('debug', array(
'engine' => 'FileLog',
'types' => array('notice', 'info', 'debug'),
'file' => 'debug',
));
CakeLog::config('error', array(
'engine' => 'FileLog',
'types' => array('error', 'warning'),
'file' => 'error',
));
}
protected function _deleteLogs() { protected function _deleteLogs() {
@unlink(LOGS . 'shops.log'); if (file_exists(LOGS . 'shops.log')) {
@unlink(LOGS . 'error.log'); unlink(LOGS . 'shops.log');
@unlink(LOGS . 'debug.log'); }
if (file_exists(LOGS . 'error.log')) {
unlink(LOGS . 'error.log');
}
if (file_exists(LOGS . 'debug.log')) {
unlink(LOGS . 'debug.log');
}
} }
/** /**
@ -301,16 +320,7 @@ class CakeLogTest extends CakeTestCase {
unlink(LOGS . 'debug.log'); unlink(LOGS . 'debug.log');
} }
CakeLog::config('debug', array( $this->_resetLogConfig();
'engine' => 'FileLog',
'types' => array('notice', 'info', 'debug'),
'file' => 'debug',
));
CakeLog::config('error', array(
'engine' => 'FileLog',
'types' => array('error', 'warning'),
'file' => 'error',
));
CakeLog::config('shops', array( CakeLog::config('shops', array(
'engine' => 'FileLog', 'engine' => 'FileLog',
'types' => array('info', 'notice', 'warning'), 'types' => array('info', 'notice', 'warning'),
@ -372,16 +382,7 @@ class CakeLogTest extends CakeTestCase {
unlink(LOGS . 'debug.log'); unlink(LOGS . 'debug.log');
} }
CakeLog::config('debug', array( $this->_resetLogConfig();
'engine' => 'FileLog',
'types' => array('notice', 'info', 'debug'),
'file' => 'debug',
));
CakeLog::config('error', array(
'engine' => 'FileLog',
'types' => array('error', 'warning'),
'file' => 'error',
));
CakeLog::config('shops', array( CakeLog::config('shops', array(
'engine' => 'FileLog', 'engine' => 'FileLog',
'types' => array('info', 'notice', 'warning'), 'types' => array('info', 'notice', 'warning'),
@ -433,8 +434,7 @@ class CakeLogTest extends CakeTestCase {
* test convenience methods * test convenience methods
*/ */
public function testConvenienceMethods() { public function testConvenienceMethods() {
@unlink(LOGS . 'error.log'); $this->_deleteLogs();
@unlink(LOGS . 'debug.log');
CakeLog::config('debug', array( CakeLog::config('debug', array(
'engine' => 'FileLog', 'engine' => 'FileLog',