From 11bfb99b0a4496f53b75a822ee2699ffe7f2b32c Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Thu, 11 Jul 2024 09:19:16 +0300 Subject: [PATCH] Update code used to retrieve last error in the logs --- app/Utils/SystemHealth.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/Utils/SystemHealth.php b/app/Utils/SystemHealth.php index 7c2c60f328cc..c415d36903d4 100644 --- a/app/Utils/SystemHealth.php +++ b/app/Utils/SystemHealth.php @@ -11,6 +11,8 @@ namespace App\Utils; +use LimitIterator; +use SplFileObject; use App\Libraries\MultiDB; use App\Mail\TestMailServer; use Exception; @@ -337,11 +339,12 @@ class SystemHealth public static function lastError() { - $filepath = storage_path('logs/laravel.log'); - $file = escapeshellarg($filepath); - $end_of_file = `tail -n 500 $file`; + $log_file = new SplFileObject(sprintf('%s/laravel.log', base_path('storage/logs'))); + $log_file->seek(PHP_INT_MAX); + $last_line = $log_file->key(); - $lines = explode("\n", $end_of_file); + $lines = new LimitIterator($log_file, max(0, $last_line - 500), $last_line); + $log_lines = iterator_to_array($lines); $last_error = ''; foreach ($lines as $line) {