@@ -14,6 +14,11 @@ class LaravelLogViewer
1414 */
1515 private static $ file ;
1616
17+ /**
18+ * @var string folder
19+ */
20+ private static $ folder ;
21+
1722 private static $ levels_classes = [
1823 'debug ' => 'info ' ,
1924 'info ' => 'info ' ,
@@ -59,6 +64,18 @@ class LaravelLogViewer
5964
6065 const MAX_FILE_SIZE = 52428800 ; // Why? Uh... Sorry
6166
67+ /**
68+ * @param string $folder
69+ */
70+ public static function setFolder ($ folder )
71+ {
72+ $ logsPath = storage_path ('logs ' ) . '/ ' . $ folder ;
73+
74+ if (app ('files ' )->exists ($ logsPath )) {
75+ self ::$ folder = $ folder ;
76+ }
77+ }
78+
6279 /**
6380 * @param string $file
6481 */
@@ -79,7 +96,8 @@ public static function setFile($file)
7996 public static function pathToLogFile ($ file )
8097 {
8198 $ logsPath = storage_path ('logs ' );
82-
99+ $ logsPath .= (self ::$ folder ) ? '/ ' . self ::$ folder : '' ;
100+
83101 if (app ('files ' )->exists ($ file )) { // try the absolute path
84102 return $ file ;
85103 }
@@ -94,6 +112,14 @@ public static function pathToLogFile($file)
94112 return $ file ;
95113 }
96114
115+ /**
116+ * @return string
117+ */
118+ public static function getFolderName ()
119+ {
120+ return self ::$ folder ;
121+ }
122+
97123 /**
98124 * @return string
99125 */
@@ -112,7 +138,7 @@ public static function all()
112138 $ pattern = '/\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}([\+-]\d{4})?\].*/ ' ;
113139
114140 if (!self ::$ file ) {
115- $ log_file = self ::getFiles ();
141+ $ log_file = (! self ::$ folder ) ? self :: getFiles () : self :: getFolderFiles ();
116142 if (!count ($ log_file )) {
117143 return [];
118144 }
@@ -180,14 +206,37 @@ public static function all()
180206 return array_reverse ($ log );
181207 }
182208
209+ /**
210+ * @return array
211+ */
212+ public static function getFolders ()
213+ {
214+ $ folders = glob (storage_path () . '/logs/* ' , GLOB_ONLYDIR );
215+ if (is_array ($ folders )) {
216+ foreach ($ folders as $ k => $ folder ) {
217+ $ folders [$ k ] = basename ($ folder );
218+ }
219+ }
220+ return array_values ($ folders );
221+ }
222+
223+ /**
224+ * @param bool $basename
225+ * @return array
226+ */
227+ public static function getFolderFiles ($ basename = false )
228+ {
229+ return self ::getFiles ($ basename , self ::$ folder );
230+ }
231+
183232 /**
184233 * @param bool $basename
185234 * @return array
186235 */
187- public static function getFiles ($ basename = false )
236+ public static function getFiles ($ basename = false , $ folder = '' )
188237 {
189238 $ pattern = function_exists ('config ' ) ? config ('logviewer.pattern ' , '*.log ' ) : '*.log ' ;
190- $ files = glob (storage_path () . '/logs/ ' . $ pattern , preg_match ('/\{.*?\,.*?\}/i ' , $ pattern ) ? GLOB_BRACE : 0 );
239+ $ files = glob (storage_path () . '/logs/ ' . $ folder . ' / ' . $ pattern , preg_match ('/\{.*?\,.*?\}/i ' , $ pattern ) ? GLOB_BRACE : 0 );
191240 $ files = array_reverse ($ files );
192241 $ files = array_filter ($ files , 'is_file ' );
193242 if ($ basename && is_array ($ files )) {
0 commit comments