11<?php
22namespace Rap2hpoutre \LaravelLogViewer ;
33
4- use Psr \Log \LogLevel ;
5-
64/**
75 * Class LaravelLogViewer
86 * @package Rap2hpoutre\LaravelLogViewer
@@ -12,14 +10,14 @@ class LaravelLogViewer
1210 /**
1311 * @var string file
1412 */
15- private static $ file ;
13+ private $ file ;
1614
1715 /**
1816 * @var string folder
1917 */
20- private static $ folder ;
18+ private $ folder ;
2119
22- private static $ levels_classes = [
20+ private $ levels_classes = [
2321 'debug ' => 'info ' ,
2422 'info ' => 'info ' ,
2523 'notice ' => 'info ' ,
@@ -32,7 +30,7 @@ class LaravelLogViewer
3230 'failed ' => 'warning ' ,
3331 ];
3432
35- private static $ levels_imgs = [
33+ private $ levels_imgs = [
3634 'debug ' => 'info-circle ' ,
3735 'info ' => 'info-circle ' ,
3836 'notice ' => 'info-circle ' ,
@@ -49,7 +47,7 @@ class LaravelLogViewer
4947 * Log levels that are used
5048 * @var array
5149 */
52- private static $ log_levels = [
50+ private $ log_levels = [
5351 'emergency ' ,
5452 'alert ' ,
5553 'critical ' ,
@@ -67,24 +65,25 @@ class LaravelLogViewer
6765 /**
6866 * @param string $folder
6967 */
70- public static function setFolder ($ folder )
68+ public function setFolder ($ folder )
7169 {
7270 $ logsPath = storage_path ('logs ' ) . '/ ' . $ folder ;
7371
7472 if (app ('files ' )->exists ($ logsPath )) {
75- self :: $ folder = $ folder ;
73+ $ this -> folder = $ folder ;
7674 }
7775 }
7876
7977 /**
8078 * @param string $file
79+ * @throws \Exception
8180 */
82- public static function setFile ($ file )
81+ public function setFile ($ file )
8382 {
84- $ file = self :: pathToLogFile ($ file );
83+ $ file = $ this -> pathToLogFile ($ file );
8584
8685 if (app ('files ' )->exists ($ file )) {
87- self :: $ file = $ file ;
86+ $ this -> file = $ file ;
8887 }
8988 }
9089
@@ -93,10 +92,10 @@ public static function setFile($file)
9392 * @return string
9493 * @throws \Exception
9594 */
96- public static function pathToLogFile ($ file )
95+ public function pathToLogFile ($ file )
9796 {
9897 $ logsPath = storage_path ('logs ' );
99- $ logsPath .= (self :: $ folder ) ? '/ ' . self :: $ folder : '' ;
98+ $ logsPath .= ($ this -> folder ) ? '/ ' . $ this -> folder : '' ;
10099
101100 if (app ('files ' )->exists ($ file )) { // try the absolute path
102101 return $ file ;
@@ -115,39 +114,39 @@ public static function pathToLogFile($file)
115114 /**
116115 * @return string
117116 */
118- public static function getFolderName ()
117+ public function getFolderName ()
119118 {
120- return self :: $ folder ;
119+ return $ this -> folder ;
121120 }
122121
123122 /**
124123 * @return string
125124 */
126- public static function getFileName ()
125+ public function getFileName ()
127126 {
128- return basename (self :: $ file );
127+ return basename ($ this -> file );
129128 }
130129
131130 /**
132131 * @return array
133132 */
134- public static function all ()
133+ public function all ()
135134 {
136135 $ log = array ();
137136
138137 $ pattern = '/\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}([\+-]\d{4})?\].*/ ' ;
139138
140- if (!self :: $ file ) {
141- $ log_file = (!self :: $ folder ) ? self :: getFiles () : self :: getFolderFiles ();
139+ if (!$ this -> file ) {
140+ $ log_file = (!$ this -> folder ) ? $ this -> getFiles () : $ this -> getFolderFiles ();
142141 if (!count ($ log_file )) {
143142 return [];
144143 }
145- self :: $ file = $ log_file [0 ];
144+ $ this -> file = $ log_file [0 ];
146145 }
147146
148- if (app ('files ' )->size (self :: $ file ) > self ::MAX_FILE_SIZE ) return null ;
147+ if (app ('files ' )->size ($ this -> file ) > self ::MAX_FILE_SIZE ) return null ;
149148
150- $ file = app ('files ' )->get (self :: $ file );
149+ $ file = app ('files ' )->get ($ this -> file );
151150
152151 preg_match_all ($ pattern , $ file , $ headings );
153152
@@ -163,7 +162,7 @@ public static function all()
163162
164163 foreach ($ headings as $ h ) {
165164 for ($ i =0 , $ j = count ($ h ); $ i < $ j ; $ i ++) {
166- foreach (self :: $ log_levels as $ level ) {
165+ foreach ($ this -> log_levels as $ level ) {
167166 if (strpos (strtolower ($ h [$ i ]), '. ' . $ level ) || strpos (strtolower ($ h [$ i ]), $ level . ': ' )) {
168167
169168 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 );
@@ -172,8 +171,8 @@ public static function all()
172171 $ log [] = array (
173172 'context ' => $ current [3 ],
174173 'level ' => $ level ,
175- 'level_class ' => self :: $ levels_classes [$ level ],
176- 'level_img ' => self :: $ levels_imgs [$ level ],
174+ 'level_class ' => $ this -> levels_classes [$ level ],
175+ 'level_img ' => $ this -> levels_imgs [$ level ],
177176 'date ' => $ current [1 ],
178177 'text ' => $ current [4 ],
179178 'in_file ' => isset ($ current [5 ]) ? $ current [5 ] : null ,
@@ -209,7 +208,7 @@ public static function all()
209208 /**
210209 * @return array
211210 */
212- public static function getFolders ()
211+ public function getFolders ()
213212 {
214213 $ folders = glob (storage_path () . '/logs/* ' , GLOB_ONLYDIR );
215214 if (is_array ($ folders )) {
@@ -224,16 +223,17 @@ public static function getFolders()
224223 * @param bool $basename
225224 * @return array
226225 */
227- public static function getFolderFiles ($ basename = false )
226+ public function getFolderFiles ($ basename = false )
228227 {
229- return self :: getFiles ($ basename , self :: $ folder );
228+ return $ this -> getFiles ($ basename , $ this -> folder );
230229 }
231230
232231 /**
233232 * @param bool $basename
233+ * @param string $folder
234234 * @return array
235235 */
236- public static function getFiles ($ basename = false , $ folder = '' )
236+ public function getFiles ($ basename = false , $ folder = '' )
237237 {
238238 $ pattern = function_exists ('config ' ) ? config ('logviewer.pattern ' , '*.log ' ) : '*.log ' ;
239239 $ files = glob (storage_path () . '/logs/ ' . $ folder . '/ ' . $ pattern , preg_match ('/\{.*?\,.*?\}/i ' , $ pattern ) ? GLOB_BRACE : 0 );
0 commit comments