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 | ]; |
||
28 | |||
29 | private static $levels_imgs = [ |
||
30 | 'debug' => 'info-circle', |
||
31 | 'info' => 'info-circle', |
||
32 | 'notice' => 'info-circle', |
||
33 | 'warning' => 'exclamation-triangle', |
||
34 | 'error' => 'exclamation-triangle', |
||
35 | 'critical' => 'exclamation-triangle', |
||
36 | 'alert' => 'exclamation-triangle', |
||
37 | 'emergency' => 'exclamation-triangle', |
||
38 | 'processed' => 'info-circle' |
||
39 | ]; |
||
40 | |||
41 | /** |
||
42 | * Log levels that are used |
||
43 | * @var array |
||
44 | */ |
||
45 | private static $log_levels = [ |
||
46 | 'emergency', |
||
47 | 'alert', |
||
48 | 'critical', |
||
49 | 'error', |
||
50 | 'warning', |
||
51 | 'notice', |
||
52 | 'info', |
||
53 | 'debug', |
||
54 | 'processed' |
||
55 | ]; |
||
56 | |||
57 | const MAX_FILE_SIZE = 52428800; // Why? Uh... Sorry |
||
58 | |||
59 | /** |
||
60 | * @param string $file |
||
61 | */ |
||
62 | public static function setFile($file) |
||
63 | { |
||
64 | $file = self::pathToLogFile($file); |
||
65 | |||
66 | if (app('files')->exists($file)) { |
||
67 | self::$file = $file; |
||
68 | } |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * @param string $file |
||
73 | * @return string |
||
74 | * @throws \Exception |
||
75 | */ |
||
76 | public static function pathToLogFile($file) |
||
77 | { |
||
78 | $logsPath = storage_path('logs'); |
||
79 | |||
80 | if (app('files')->exists($file)) { // try the absolute path |
||
81 | return $file; |
||
82 | } |
||
83 | |||
84 | $file = $logsPath . '/' . $file; |
||
85 | |||
86 | // check if requested file is really in the logs directory |
||
87 | if (dirname($file) !== $logsPath) { |
||
88 | throw new \Exception('No such log file'); |
||
89 | } |
||
90 | |||
91 | return $file; |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * @return string |
||
96 | */ |
||
97 | public static function getFileName() |
||
101 | |||
102 | /** |
||
103 | * @return array |
||
104 | */ |
||
105 | public static function all() |
||
158 | |||
159 | /** |
||
160 | * @param bool $basename |
||
161 | * @return array |
||
162 | */ |
||
163 | public static function getFiles($basename = false) |
||
175 | } |
||
176 |