11<?php
2+
23namespace Rap2hpoutre \LaravelLogViewer ;
34
45/**
@@ -17,50 +18,23 @@ class LaravelLogViewer
1718 */
1819 private $ folder ;
1920
20- private $ levels_classes = [
21- 'debug ' => 'info ' ,
22- 'info ' => 'info ' ,
23- 'notice ' => 'info ' ,
24- 'warning ' => 'warning ' ,
25- 'error ' => 'danger ' ,
26- 'critical ' => 'danger ' ,
27- 'alert ' => 'danger ' ,
28- 'emergency ' => 'danger ' ,
29- 'processed ' => 'info ' ,
30- 'failed ' => 'warning ' ,
31- ];
32-
33- private $ levels_imgs = [
34- 'debug ' => 'info-circle ' ,
35- 'info ' => 'info-circle ' ,
36- 'notice ' => 'info-circle ' ,
37- 'warning ' => 'exclamation-triangle ' ,
38- 'error ' => 'exclamation-triangle ' ,
39- 'critical ' => 'exclamation-triangle ' ,
40- 'alert ' => 'exclamation-triangle ' ,
41- 'emergency ' => 'exclamation-triangle ' ,
42- 'processed ' => 'info-circle ' ,
43- 'failed ' => 'exclamation-triangle '
44- ];
21+ /**
22+ * Why? Uh... Sorry
23+ */
24+ const MAX_FILE_SIZE = 52428800 ;
4525
4626 /**
47- * Log levels that are used
48- * @var array
27+ * @var Level level
4928 */
50- private $ log_levels = [
51- 'emergency ' ,
52- 'alert ' ,
53- 'critical ' ,
54- 'error ' ,
55- 'warning ' ,
56- 'notice ' ,
57- 'info ' ,
58- 'debug ' ,
59- 'processed ' ,
60- 'failed '
61- ];
62-
63- const MAX_FILE_SIZE = 52428800 ; // Why? Uh... Sorry
29+ private $ level ;
30+
31+ /**
32+ * LaravelLogViewer constructor.
33+ */
34+ public function __construct ()
35+ {
36+ $ this ->level = new Level ();
37+ }
6438
6539 /**
6640 * @param string $folder
@@ -95,8 +69,8 @@ public function setFile($file)
9569 public function pathToLogFile ($ file )
9670 {
9771 $ logsPath = storage_path ('logs ' );
98- $ logsPath .= ($ this ->folder ) ? '/ ' . $ this ->folder : '' ;
99-
72+ $ logsPath .= ($ this ->folder ) ? '/ ' . $ this ->folder : '' ;
73+
10074 if (app ('files ' )->exists ($ file )) { // try the absolute path
10175 return $ file ;
10276 }
@@ -138,7 +112,7 @@ public function all()
138112
139113 if (!$ this ->file ) {
140114 $ log_file = (!$ this ->folder ) ? $ this ->getFiles () : $ this ->getFolderFiles ();
141- if (!count ($ log_file )) {
115+ if (!count ($ log_file )) {
142116 return [];
143117 }
144118 $ this ->file = $ log_file [0 ];
@@ -161,8 +135,8 @@ public function all()
161135 }
162136
163137 foreach ($ headings as $ h ) {
164- for ($ i= 0 , $ j = count ($ h ); $ i < $ j ; $ i ++) {
165- foreach ($ this ->log_levels as $ level ) {
138+ for ($ i = 0 , $ j = count ($ h ); $ i < $ j ; $ i ++) {
139+ foreach ($ this ->level -> all () as $ level ) {
166140 if (strpos (strtolower ($ h [$ i ]), '. ' . $ level ) || strpos (strtolower ($ h [$ i ]), $ level . ': ' )) {
167141
168142 preg_match ('/^\[(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}([\+-]\d{4})?)\](?:.*?(\w+)\.|.*?) ' . $ level . ': (.*?)( in .*?:[0-9]+)?$/i ' , $ h [$ i ], $ current );
@@ -171,8 +145,8 @@ public function all()
171145 $ log [] = array (
172146 'context ' => $ current [3 ],
173147 'level ' => $ level ,
174- 'level_class ' => $ this ->levels_classes [ $ level] ,
175- 'level_img ' => $ this ->levels_imgs [ $ level] ,
148+ 'level_class ' => $ this ->level -> cssClass ( $ level) ,
149+ 'level_img ' => $ this ->level -> img ( $ level) ,
176150 'date ' => $ current [1 ],
177151 'text ' => $ current [4 ],
178152 'in_file ' => isset ($ current [5 ]) ? $ current [5 ] : null ,
@@ -188,13 +162,13 @@ public function all()
188162 $ lines = explode (PHP_EOL , $ file );
189163 $ log = [];
190164
191- foreach ($ lines as $ key => $ line ) {
165+ foreach ($ lines as $ key => $ line ) {
192166 $ log [] = [
193167 'context ' => '' ,
194168 'level ' => '' ,
195169 'level_class ' => '' ,
196170 'level_img ' => '' ,
197- 'date ' => $ key+ 1 ,
171+ 'date ' => $ key + 1 ,
198172 'text ' => $ line ,
199173 'in_file ' => null ,
200174 'stack ' => '' ,
0 commit comments