diff --git a/src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php b/src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php index eabf443..bb99dbd 100644 --- a/src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php +++ b/src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php @@ -47,16 +47,7 @@ public static function all() $pattern = '/\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\].*/'; - - if (!self::$file) { - $log_file = self::getFiles(); - if(!count($log_file)) { - return []; - } - self::$file = $log_file[0]; - } - - $file = File::get(self::$file); + $file = self::getCurrentFile(); preg_match_all($pattern, $file, $headings); @@ -96,8 +87,7 @@ public static function all() $level = strtoupper($ll); preg_match('/^\[(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\].*?\.' . $level . ': (.*?)( in .*?:[0-9]+)?$/', $h[$i], $current); - - + $log[] = array( 'level' => $ll, 'level_class' => $levels_classes[$ll], @@ -113,8 +103,7 @@ public static function all() } } - $log = array_reverse($log); - return $log; + return array_reverse($log); } /** @@ -132,4 +121,20 @@ public static function getFiles($basename = false) } return $files; } + + /** + * @return array + */ + private static function getCurrentFile() + { + if (!self::$file) { + $log_file = self::getFiles(); + if(!count($log_file)) { + return []; + } + self::$file = $log_file[0]; + } + + return File::get(self::$file); + } }