1 | <?php |
||
10 | class LaravelLogViewer |
||
11 | { |
||
12 | /** |
||
13 | * @var string file |
||
14 | */ |
||
15 | private static $file; |
||
16 | |||
17 | private static $levels_classes = [ |
||
18 | 'debug' => 'info', |
||
19 | 'info' => 'info', |
||
20 | 'notice' => 'info', |
||
21 | 'warning' => 'warning', |
||
22 | 'error' => 'danger', |
||
23 | 'critical' => 'danger', |
||
24 | 'alert' => 'danger', |
||
25 | 'emergency' => 'danger', |
||
26 | 'processed' => 'info', |
||
27 | 'failed' => 'warning', |
||
28 | ]; |
||
29 | |||
30 | private static $levels_imgs = [ |
||
31 | 'debug' => 'info-circle', |
||
32 | 'info' => 'info-circle', |
||
33 | 'notice' => 'info-circle', |
||
34 | 'warning' => 'exclamation-triangle', |
||
35 | 'error' => 'exclamation-triangle', |
||
36 | 'critical' => 'exclamation-triangle', |
||
37 | 'alert' => 'exclamation-triangle', |
||
38 | 'emergency' => 'exclamation-triangle', |
||
39 | 'processed' => 'info-circle', |
||
40 | 'failed' => 'exclamation-triangle' |
||
41 | ]; |
||
42 | |||
43 | /** |
||
44 | * Log levels that are used |
||
45 | * @var array |
||
46 | */ |
||
47 | private static $log_levels = [ |
||
48 | 'emergency', |
||
49 | 'alert', |
||
50 | 'critical', |
||
51 | 'error', |
||
52 | 'warning', |
||
53 | 'notice', |
||
54 | 'info', |
||
55 | 'debug', |
||
56 | 'processed', |
||
57 | 'failed' |
||
58 | ]; |
||
59 | |||
60 | const MAX_FILE_SIZE = 52428800; // Why? Uh... Sorry |
||
61 | |||
62 | /** |
||
63 | * @param string $file |
||
64 | */ |
||
65 | public static function setFile($file) |
||
73 | |||
74 | /** |
||
75 | * @param string $file |
||
76 | * @return string |
||
77 | * @throws \Exception |
||
78 | */ |
||
79 | public static function pathToLogFile($file) |
||
80 | { |
||
81 | $logsPath = storage_path('logs'); |
||
82 | |||
83 | if (app('files')->exists($file)) { // try the absolute path |
||
84 | return $file; |
||
85 | } |
||
86 | |||
87 | $file = $logsPath . '/' . $file; |
||
88 | |||
89 | // check if requested file is really in the logs directory |
||
90 | if (dirname($file) !== $logsPath) { |
||
91 | throw new \Exception('No such log file'); |
||
92 | } |
||
93 | |||
94 | return $file; |
||
95 | } |
||
96 | |||
97 | /** |
||
98 | * @return string |
||
99 | */ |
||
100 | public static function getFileName() |
||
104 | |||
105 | /** |
||
106 | * @return array |
||
107 | */ |
||
108 | public static function all() |
||
161 | |||
162 | /** |
||
163 | * @param bool $basename |
||
164 | * @return array |
||
165 | */ |
||
166 | public static function getFiles($basename = false) |
||
178 | } |
||
179 |