@@ -61,26 +61,58 @@ protected function getLaravelLogFilePaths(): array
61
61
);
62
62
}
63
63
$ files = [];
64
+ $ filePathsCollected = [];
65
+
66
+ foreach (config ('log-viewer.include_files ' , []) as $ pattern => $ alias ) {
67
+ if (is_numeric ($ pattern )) {
68
+ $ pattern = $ alias ;
69
+ $ alias = null ;
70
+ }
64
71
65
- foreach (config ('log-viewer.include_files ' , []) as $ pattern ) {
66
72
if (! str_starts_with ($ pattern , DIRECTORY_SEPARATOR )) {
67
73
$ pattern = $ baseDir .$ pattern ;
68
74
}
69
75
70
- $ files = array_merge ($ files , $ this ->getFilePathsMatchingPattern ($ pattern ));
76
+ $ filesMatchingPattern = $ this ->getFilePathsMatchingPattern ($ pattern );
77
+ $ filesMatchingPattern = array_map ('realpath ' , $ filesMatchingPattern );
78
+ $ filesMatchingPattern = array_values (array_filter ($ filesMatchingPattern , 'is_file ' ));
79
+ $ filesMatchingPattern = array_values (array_diff ($ filesMatchingPattern , $ filePathsCollected ));
80
+ $ filePathsCollected = array_merge ($ filePathsCollected , $ filesMatchingPattern );
81
+
82
+ // Let's prep aliases if they are provided.
83
+ if (! empty ($ alias )) {
84
+ $ filesMatchingPattern = array_map (fn ($ path ) => [$ path , $ alias ], $ filesMatchingPattern );
85
+ }
86
+
87
+ $ files = array_merge ($ files , $ filesMatchingPattern );
71
88
}
72
89
73
- foreach (config ('log-viewer.exclude_files ' , []) as $ pattern ) {
90
+ foreach (config ('log-viewer.exclude_files ' , []) as $ pattern => $ alias ) {
91
+ if (is_numeric ($ pattern )) {
92
+ $ pattern = $ alias ;
93
+ $ alias = null ;
94
+ }
95
+
74
96
if (! str_starts_with ($ pattern , DIRECTORY_SEPARATOR )) {
75
97
$ pattern = $ baseDir .$ pattern ;
76
98
}
77
99
78
- $ files = array_diff ($ files , $ this ->getFilePathsMatchingPattern ($ pattern ));
79
- }
100
+ $ filesMatchingPattern = $ this ->getFilePathsMatchingPattern ($ pattern );
101
+ $ filesMatchingPattern = array_map ('realpath ' , $ filesMatchingPattern );
102
+ $ filesMatchingPattern = array_values (array_filter ($ filesMatchingPattern , 'is_file ' ));
103
+
104
+ if (! empty ($ alias )) {
105
+ $ filesMatchingPattern = array_map (fn ($ path ) => [$ path , $ alias ], $ filesMatchingPattern );
106
+ }
80
107
81
- $ files = array_map ('realpath ' , $ files );
108
+ $ files = array_filter ($ files , function (string |array $ file ) use ($ filesMatchingPattern ) {
109
+ if (is_array ($ file )) {
110
+ return ! in_array ($ file [0 ], $ filesMatchingPattern );
111
+ }
82
112
83
- $ files = array_filter ($ files , 'is_file ' );
113
+ return ! in_array ($ file , $ filesMatchingPattern );
114
+ });
115
+ }
84
116
85
117
return array_values (array_reverse ($ files ));
86
118
}
@@ -111,7 +143,13 @@ public function getFiles(): LogFileCollection
111
143
112
144
$ this ->_cachedFiles = (new LogFileCollection ($ this ->getLaravelLogFilePaths ()))
113
145
->unique ()
114
- ->map (fn ($ filePath ) => new $ fileClass ($ filePath ))
146
+ ->map (function ($ filePath ) use ($ fileClass ) {
147
+ if (is_array ($ filePath )) {
148
+ [$ filePath , $ alias ] = $ filePath ;
149
+ }
150
+
151
+ return new $ fileClass ($ filePath , null , $ alias ?? null );
152
+ })
115
153
->values ();
116
154
117
155
if (config ('log-viewer.hide_unknown_files ' , true )) {
0 commit comments