Skip to content

Commit 5898047

Browse files
committed
Update LaravelLogViewer.php
1 parent c8517d9 commit 5898047

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@
77

88
class LaravelLogViewer
99
{
10+
11+
private static $file;
12+
13+
public static function setFile($file)
14+
{
15+
if (File::exists(storage_path() . '/logs/' . $file)) {
16+
self::$file = storage_path() . '/logs/' . $file;
17+
}
18+
}
19+
1020
public static function all()
1121
{
1222
$log = array();
@@ -16,9 +26,14 @@ public static function all()
1626

1727
$pattern = '/\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\].*/';
1828

19-
$log_file = storage_path() . '/logs/laravel.log';
29+
if (self::$file) {
30+
$file = File::get(self::$file);
31+
} else {
32+
$log_file = self::getFiles();
33+
$file = File::get($log_file[0]);
34+
}
35+
2036

21-
$file = File::get($log_file);
2237

2338
preg_match_all($pattern, $file, $headings);
2439

@@ -65,7 +80,7 @@ public static function all()
6580
'date' => $current[1],
6681
'text' => $current[2],
6782
'in_file' => isset($current[3]) ? $current[3] : null,
68-
'stack' => $log_data[$i]
83+
'stack' => $log_data[$i],
6984
);
7085
}
7186
}
@@ -75,4 +90,16 @@ public static function all()
7590
$log = array_reverse($log);
7691
return $log;
7792
}
78-
}
93+
94+
public static function getFiles($basename = false)
95+
{
96+
$files = glob(storage_path() . '/logs/*');
97+
$files = array_reverse($files);
98+
if ($basename && is_array($files)) {
99+
foreach ($files as $k => $file) {
100+
$files[$k] = basename($file);
101+
}
102+
}
103+
return $files;
104+
}
105+
}

0 commit comments

Comments
 (0)