Skip to content

Commit

Permalink
Fix bug when filename change still was writing inside old file
Browse files Browse the repository at this point in the history
  • Loading branch information
thecodeholic committed Apr 15, 2021
1 parent 0d7e384 commit 1167cb4
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions FileLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;


/**
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 1167cb4

Please sign in to comment.