Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

minor updates to the logging changeset

- change usage of Set to Hash
- updating bootstrap.php
- adding docblocks
- avoid silencing unlink errors in tests
  • Loading branch information...
commit e5b33627d57c28c9131b87f23d22d24567ab37b4 1 parent 912a5f6
@rchavik rchavik authored
View
1  app/Config/bootstrap.php
@@ -155,6 +155,7 @@
/**
* Configures default file logging options
*/
+App::uses('CakeLog', 'Log');
CakeLog::config('debug', array(
'engine' => 'FileLog',
'types' => array('notice', 'info', 'debug'),
View
1  lib/Cake/Console/Templates/skel/Config/bootstrap.php
@@ -95,6 +95,7 @@
/**
* Configures default file logging options
*/
+App::uses('CakeLog', 'Log');
CakeLog::config('debug', array(
'engine' => 'FileLog',
'scopes' => array('notice', 'info', 'debug'),
View
15 lib/Cake/Log/CakeLog.php
@@ -219,9 +219,6 @@ public static function stream($streamName) {
* @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 @@ public static function write($type, $message, $scope = array()) {
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) {
@jadb Collaborator
jadb added a note

Why does it now need to implement CakeLog all of a sudden for $logger->config() to run? Can't it check for the method if it exists instead of forcing to be an instanceof BaseLog? Breaks scopes for custom loggers that only implement CakeLogInterface but do not extend BaseLog or FileLog, as per the documentation.

@markstory Owner

config() wasn't part of the interface so that's why it doesn't check against the interface. I agree a method check might be a better way to do this though.

@markstory Owner

Changed in a6441d7

@jadb Collaborator
jadb added a note

:100:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ $config = $logger->config();
+ $types = $config['types'];
+ $scopes = $config['scopes'];
+ }
if (is_string($scope)) {
$inScope = in_array($scope, $scopes);
} else {
View
5 lib/Cake/Log/Engine/BaseLog.php
@@ -45,6 +45,11 @@ public function __construct($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
* @return array
*/
View
4 lib/Cake/Log/Engine/ConsoleLog.php
@@ -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(),
View
5 lib/Cake/Log/Engine/FileLog.php
@@ -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,
View
50 lib/Cake/Test/Case/Log/CakeLogTest.php
@@ -281,10 +281,29 @@ public function testStreamDisableInvalid() {
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 @@ public function testScopedLoggingBC() {
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 @@ public function testScopedLogging() {
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 @@ public function testScopedLogging() {
* test convenience methods
*/
public function testConvenienceMethods() {
- @unlink(LOGS . 'error.log');
- @unlink(LOGS . 'debug.log');
+ $this->_deleteLogs();
CakeLog::config('debug', array(
'engine' => 'FileLog',

0 comments on commit e5b3362

Please sign in to comment.
Something went wrong with that request. Please try again.