Skip to content

Commit

Permalink
remove autologging
Browse files Browse the repository at this point in the history
  • Loading branch information
euromark committed Sep 13, 2013
1 parent 130ccf4 commit 61b05c4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 30 deletions.
18 changes: 1 addition & 17 deletions lib/Cake/Log/CakeLog.php
Expand Up @@ -371,18 +371,6 @@ public static function stream($streamName) {
return false;
}

/**
* Configures the automatic/default stream a FileLog.
*
* @return void
*/
protected static function _autoConfig() {
self::$_Collection->load('default', array(
'engine' => 'File',
'path' => LOGS,
));
}

/**
* Writes the given message and type to all of the configured log adapters.
* Configured adapters are passed both the $type and $message variables. $type
Expand Down Expand Up @@ -454,11 +442,7 @@ public static function write($type, $message, $scope = array()) {
$logged = true;
}
}
if (!$logged) {
self::_autoConfig();
self::stream('default')->write($type, $message);
}
return true;
return $logged;
}

/**
Expand Down
28 changes: 15 additions & 13 deletions lib/Cake/Test/Case/Log/CakeLogTest.php
Expand Up @@ -126,27 +126,20 @@ public function testNotImplementingInterface() {
}

/**
* Test that CakeLog autoconfigures itself to use a FileLogger with the LOGS dir.
* When no streams are there.
* Test that CakeLog does not auto create logs when no streams are there to listen.
*
* @return void
*/
public function testAutoConfig() {
public function testNoStreamListenting() {
if (file_exists(LOGS . 'error.log')) {
unlink(LOGS . 'error.log');
}
CakeLog::write(LOG_WARNING, 'Test warning');
$this->assertTrue(file_exists(LOGS . 'error.log'));
$res = CakeLog::write(LOG_WARNING, 'Test warning');
$this->assertFalse($res);
$this->assertFalse(file_exists(LOGS . 'error.log'));

$result = CakeLog::configured();
$this->assertEquals(array('default'), $result);

$testMessage = 'custom message';
CakeLog::write('custom', $testMessage);
$content = file_get_contents(LOGS . 'custom.log');
$this->assertContains($testMessage, $content);
unlink(LOGS . 'error.log');
unlink(LOGS . 'custom.log');
$this->assertEquals(array(), $result);
}

/**
Expand Down Expand Up @@ -197,6 +190,10 @@ public function testDrop() {
* @return void
*/
public function testLogFileWriting() {
CakeLog::config('file', array(
'engine' => 'File',
'path' => LOGS
));
if (file_exists(LOGS . 'error.log')) {
unlink(LOGS . 'error.log');
}
Expand Down Expand Up @@ -503,6 +500,11 @@ public function testBogusTypeAndScope() {
$this->_resetLogConfig();
$this->_deleteLogs();

CakeLog::config('file', array(
'engine' => 'File',
'path' => LOGS
));

CakeLog::write('bogus', 'bogus message');
$this->assertTrue(file_exists(LOGS . 'bogus.log'));
$this->assertFalse(file_exists(LOGS . 'error.log'));
Expand Down

0 comments on commit 61b05c4

Please sign in to comment.