From 8060f1b4be38020259ab0a33a44d58184b956ec8 Mon Sep 17 00:00:00 2001 From: Schlaefer Date: Sun, 6 Oct 2013 15:04:57 +0200 Subject: [PATCH] fixes FileLog doesn't delete on rotation if `rotate` = 0 --- lib/Cake/Log/Engine/FileLog.php | 14 +++++++++----- lib/Cake/Test/Case/Log/Engine/FileLogTest.php | 1 + 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/Cake/Log/Engine/FileLog.php b/lib/Cake/Log/Engine/FileLog.php index 22c1a9992..ad58963a0 100644 --- a/lib/Cake/Log/Engine/FileLog.php +++ b/lib/Cake/Log/Engine/FileLog.php @@ -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; } } diff --git a/lib/Cake/Test/Case/Log/Engine/FileLogTest.php b/lib/Cake/Test/Case/Log/Engine/FileLogTest.php index 4eba6cfad..11785aa21 100644 --- a/lib/Cake/Test/Case/Log/Engine/FileLogTest.php +++ b/lib/Cake/Test/Case/Log/Engine/FileLogTest.php @@ -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'));