mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
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:
parent
912a5f6d12
commit
e5b33627d5
7 changed files with 47 additions and 34 deletions
|
@ -155,6 +155,7 @@ Configure::write('Dispatcher.filters', array(
|
|||
/**
|
||||
* Configures default file logging options
|
||||
*/
|
||||
App::uses('CakeLog', 'Log');
|
||||
CakeLog::config('debug', array(
|
||||
'engine' => 'FileLog',
|
||||
'types' => array('notice', 'info', 'debug'),
|
||||
|
|
|
@ -95,6 +95,7 @@ Configure::write('Dispatcher.filters', array(
|
|||
/**
|
||||
* Configures default file logging options
|
||||
*/
|
||||
App::uses('CakeLog', 'Log');
|
||||
CakeLog::config('debug', array(
|
||||
'engine' => 'FileLog',
|
||||
'scopes' => array('notice', 'info', 'debug'),
|
||||
|
|
|
@ -219,9 +219,6 @@ class CakeLog {
|
|||
* @return void
|
||||
*/
|
||||
protected static function _autoConfig() {
|
||||
if (empty(self::$_Collection)) {
|
||||
self::_init();
|
||||
}
|
||||
self::$_Collection->load('error', array(
|
||||
'engine' => 'FileLog',
|
||||
'types' => array('error', 'warning'),
|
||||
|
@ -275,14 +272,18 @@ class CakeLog {
|
|||
if (is_string($type) && empty($scope) && !in_array($type, $levels)) {
|
||||
$scope = $type;
|
||||
}
|
||||
if (empty(self::$_streams)) {
|
||||
if (!self::$_Collection->attached()) {
|
||||
self::_autoConfig();
|
||||
}
|
||||
foreach (self::$_Collection->enabled() as $streamName) {
|
||||
$logger = self::$_Collection->{$streamName};
|
||||
$config = $logger->config();
|
||||
$types = $config['types'];
|
||||
$scopes = $config['scopes'];
|
||||
$types = null;
|
||||
$scopes = array();
|
||||
if ($logger instanceof BaseLog) {
|
||||
$config = $logger->config();
|
||||
$types = $config['types'];
|
||||
$scopes = $config['scopes'];
|
||||
}
|
||||
if (is_string($scope)) {
|
||||
$inScope = in_array($scope, $scopes);
|
||||
} else {
|
||||
|
|
|
@ -45,6 +45,11 @@ abstract class BaseLog implements CakeLogInterface {
|
|||
/**
|
||||
* 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
|
||||
* @return array
|
||||
*/
|
||||
|
|
|
@ -39,6 +39,8 @@ class ConsoleLog extends BaseLog {
|
|||
*
|
||||
* 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.
|
||||
* - `outputAs` integer or ConsoleOutput::[RAW|PLAIN|COLOR]
|
||||
*
|
||||
|
@ -47,7 +49,7 @@ class ConsoleLog extends BaseLog {
|
|||
*/
|
||||
public function __construct($config = array()) {
|
||||
parent::__construct($config);
|
||||
$config = Set::merge(array(
|
||||
$config = Hash::merge(array(
|
||||
'stream' => 'php://stderr',
|
||||
'types' => null,
|
||||
'scopes' => array(),
|
||||
|
|
|
@ -39,13 +39,16 @@ class FileLog extends BaseLog {
|
|||
*
|
||||
* 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.
|
||||
*
|
||||
* @param array $options Options for the FileLog, see above.
|
||||
*/
|
||||
public function __construct($config = array()) {
|
||||
parent::__construct($config);
|
||||
$config = Set::merge(array(
|
||||
$config = Hash::merge(array(
|
||||
'path' => LOGS,
|
||||
'file' => null,
|
||||
'types' => null,
|
||||
|
|
|
@ -281,10 +281,29 @@ class CakeLogTest extends CakeTestCase {
|
|||
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() {
|
||||
@unlink(LOGS . 'shops.log');
|
||||
@unlink(LOGS . 'error.log');
|
||||
@unlink(LOGS . 'debug.log');
|
||||
if (file_exists(LOGS . 'shops.log')) {
|
||||
unlink(LOGS . 'shops.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');
|
||||
}
|
||||
|
||||
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',
|
||||
));
|
||||
$this->_resetLogConfig();
|
||||
CakeLog::config('shops', array(
|
||||
'engine' => 'FileLog',
|
||||
'types' => array('info', 'notice', 'warning'),
|
||||
|
@ -372,16 +382,7 @@ class CakeLogTest extends CakeTestCase {
|
|||
unlink(LOGS . 'debug.log');
|
||||
}
|
||||
|
||||
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',
|
||||
));
|
||||
$this->_resetLogConfig();
|
||||
CakeLog::config('shops', array(
|
||||
'engine' => 'FileLog',
|
||||
'types' => array('info', 'notice', 'warning'),
|
||||
|
@ -433,8 +434,7 @@ class CakeLogTest extends CakeTestCase {
|
|||
* test convenience methods
|
||||
*/
|
||||
public function testConvenienceMethods() {
|
||||
@unlink(LOGS . 'error.log');
|
||||
@unlink(LOGS . 'debug.log');
|
||||
$this->_deleteLogs();
|
||||
|
||||
CakeLog::config('debug', array(
|
||||
'engine' => 'FileLog',
|
||||
|
|
Loading…
Add table
Reference in a new issue