Skip to content
Permalink
Browse files

making CakeLog to work with bogus $type and $scope

closes #2881
  • Loading branch information...
rchavik committed May 15, 2012
1 parent a37bdba commit c9b801b96d96b246c76d17759431ce654ad3b73e
Showing with 45 additions and 12 deletions.
  1. +6 −3 lib/Cake/Log/CakeLog.php
  2. +39 −9 lib/Cake/Test/Case/Log/CakeLogTest.php
@@ -416,9 +416,7 @@ public static function write($type, $message, $scope = array()) {
if (is_string($type) && empty($scope) && !in_array($type, self::$_levels)) {
$scope = $type;
}
if (!self::$_Collection->attached()) {
self::_autoConfig();
}
$logged = false;
foreach (self::$_Collection->enabled() as $streamName) {
$logger = self::$_Collection->{$streamName};
$types = null;
@@ -440,8 +438,13 @@ public static function write($type, $message, $scope = array()) {
}
if (empty($types) || in_array($type, $types) || in_array($type, $scopes) && $inScope) {
$logger->write($type, $message);
$logged = true;
}
}
if (!$logged) {
self::_autoConfig();
self::stream('default')->write($type, $message);
}
return true;
}
@@ -318,21 +318,22 @@ protected function _deleteLogs() {
if (file_exists(LOGS . 'debug.log')) {
unlink(LOGS . 'debug.log');
}
if (file_exists(LOGS . 'bogus.log')) {
unlink(LOGS . 'bogus.log');
}
if (file_exists(LOGS . 'spam.log')) {
unlink(LOGS . 'spam.log');
}
if (file_exists(LOGS . 'eggs.log')) {
unlink(LOGS . 'eggs.log');
}
}
/**
* test backward compatible scoped logging
*/
public function testScopedLoggingBC() {
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');
}
$this->_deleteLogs();
$this->_resetLogConfig();
CakeLog::config('shops', array(
@@ -446,6 +447,33 @@ public function testScopedLogging() {
CakeLog::drop('shops');
}
/**
* test bogus type and scope
*
*/
public function testBogusTypeAndScope() {
$this->_resetLogConfig();
$this->_deleteLogs();
CakeLog::write('bogus', 'bogus message');
$this->assertTrue(file_exists(LOGS . 'bogus.log'));
$this->assertFalse(file_exists(LOGS . 'error.log'));
$this->assertFalse(file_exists(LOGS . 'debug.log'));
$this->_deleteLogs();
CakeLog::write('bogus', 'bogus message', 'bogus');
$this->assertTrue(file_exists(LOGS . 'bogus.log'));
$this->assertFalse(file_exists(LOGS . 'error.log'));
$this->assertFalse(file_exists(LOGS . 'debug.log'));
$this->_deleteLogs();
CakeLog::write('error', 'bogus message', 'bogus');
$this->assertFalse(file_exists(LOGS . 'bogus.log'));
$this->assertTrue(file_exists(LOGS . 'error.log'));
$this->assertFalse(file_exists(LOGS . 'debug.log'));
$this->_deleteLogs();
}
/**
* test scoped logging with convenience methods
*/
@@ -641,6 +669,8 @@ public function testCustomLevelWrites() {
CakeLog::drop('spam');
CakeLog::drop('eggs');
$this->_deleteLogs();
}
}

0 comments on commit c9b801b

Please sign in to comment.
You can’t perform that action at this time.