From 1167cb4294181ed379f3ae998eb60ca9a8544c46 Mon Sep 17 00:00:00 2001 From: Zura Sekhniashvili Date: Thu, 15 Apr 2021 19:18:08 +0400 Subject: [PATCH] Fix bug when filename change still was writing inside old file --- FileLogger.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/FileLogger.php b/FileLogger.php index 2a8cc21..d03ad08 100644 --- a/FileLogger.php +++ b/FileLogger.php @@ -48,7 +48,7 @@ class FileLogger // Log text attributes public $logTextDateFormat = "Y-m-d H:i:s"; - public $logTextTemplate = "[ {date} | {type} ] - {message} " . PHP_EOL; + public $logTextTemplate = '[ {date} ] - [ {type} ] - {message}' . PHP_EOL; /** @@ -324,16 +324,17 @@ private function getLatestLogFile() { $files = []; if ($handle = opendir($this->logFilePath)) { - while (false !== ($file = readdir($handle))) { + $filesArray = glob($this->logFilePath."/*{$this->logFileName}"); + foreach ($filesArray as $file) { if ($file != "." && $file != ".." && $file != ".gitignore") { - $files[filemtime($this->logFilePath . '/' . $file)] = $file; + $files[filemtime($file)] = $file; } } closedir($handle); // sort sort($files); - return end($files); + return basename(end($files)); } return false;