fixes FileLog doesn't delete on rotation if rotate = 0

This commit is contained in:
Schlaefer 2013-10-06 15:04:57 +02:00
parent 83d340a3af
commit 8060f1b4be
2 changed files with 10 additions and 5 deletions

View file

@ -201,17 +201,21 @@ class FileLog extends BaseLog {
}
if ($this->_config['rotate'] === 0) {
return unlink($filepath);
$result = unlink($filepath);
} else {
$result = rename($filepath, $filepath . '.' . time());
}
if ($this->_config['rotate']) {
$files = glob($filepath . '.*');
while (count($files) >= $this->_config['rotate']) {
$files = glob($filepath . '.*');
if ($files) {
$filesToDelete = count($files) - $this->_config['rotate'];
while ($filesToDelete > 0) {
unlink(array_shift($files));
$filesToDelete--;
}
}
return rename($filepath, $filepath . '.' . time());
return $result;
}
}

View file

@ -142,6 +142,7 @@ class FileLogTest extends CakeTestCase {
'size' => 35,
'rotate' => 0
));
file_put_contents($path . 'debug.log.0000000000', "The oldest log file with over 35 bytes.\n");
$log->write('debug', 'Test debug');
$this->assertTrue(file_exists($path . 'debug.log'));