mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge pull request #1705 from Schlaefer/FileLog-RotateOlderLogs
fixes FileLog doesn't delete on rotation if count(files) is greater 'rotate'
This commit is contained in:
commit
105f032e81
2 changed files with 12 additions and 5 deletions
|
@ -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 . '.*');
|
||||
if (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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -117,6 +117,8 @@ class FileLogTest extends CakeTestCase {
|
|||
$result = file_get_contents($files[1]);
|
||||
$this->assertRegExp('/Warning: Test warning second/', $result);
|
||||
|
||||
file_put_contents($path . 'error.log.0000000000', "The oldest log file with over 35 bytes.\n");
|
||||
|
||||
sleep(1);
|
||||
clearstatcache();
|
||||
$log->write('warning', 'Test warning fourth');
|
||||
|
@ -140,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'));
|
||||
|
||||
|
|
Loading…
Reference in a new issue