|
1
|
|
|
<?php namespace Arcanedev\LogViewer; |
|
2
|
|
|
|
|
3
|
|
|
use Arcanedev\LogViewer\Contracts\Utilities\Filesystem as FilesystemContract; |
|
4
|
|
|
use Arcanedev\LogViewer\Contracts\Utilities\Factory as FactoryContract; |
|
5
|
|
|
use Arcanedev\LogViewer\Contracts\Utilities\LogLevels as LogLevelsContract; |
|
6
|
|
|
use Arcanedev\LogViewer\Contracts\LogViewer as LogViewerContract; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class LogViewer |
|
10
|
|
|
* |
|
11
|
|
|
* @package Arcanedev\LogViewer |
|
12
|
|
|
* @author ARCANEDEV <[email protected]> |
|
13
|
|
|
*/ |
|
14
|
|
|
class LogViewer implements LogViewerContract |
|
15
|
|
|
{ |
|
16
|
|
|
/* ----------------------------------------------------------------- |
|
17
|
|
|
| Constants |
|
18
|
|
|
| ----------------------------------------------------------------- |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* LogViewer Version |
|
23
|
|
|
*/ |
|
24
|
|
|
const VERSION = '4.6.2'; |
|
25
|
|
|
|
|
26
|
|
|
/* ----------------------------------------------------------------- |
|
27
|
|
|
| Properties |
|
28
|
|
|
| ----------------------------------------------------------------- |
|
29
|
|
|
*/ |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* The factory instance. |
|
33
|
|
|
* |
|
34
|
|
|
* @var \Arcanedev\LogViewer\Contracts\Utilities\Factory |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $factory; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* The filesystem instance. |
|
40
|
|
|
* |
|
41
|
|
|
* @var \Arcanedev\LogViewer\Contracts\Utilities\Filesystem |
|
42
|
|
|
*/ |
|
43
|
|
|
protected $filesystem; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* The log levels instance. |
|
47
|
|
|
* |
|
48
|
|
|
* @var \Arcanedev\LogViewer\Contracts\Utilities\LogLevels |
|
49
|
|
|
*/ |
|
50
|
|
|
protected $levels; |
|
51
|
|
|
|
|
52
|
|
|
/* ----------------------------------------------------------------- |
|
53
|
|
|
| Constructor |
|
54
|
|
|
| ----------------------------------------------------------------- |
|
55
|
|
|
*/ |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Create a new instance. |
|
59
|
|
|
* |
|
60
|
|
|
* @param \Arcanedev\LogViewer\Contracts\Utilities\Factory $factory |
|
61
|
|
|
* @param \Arcanedev\LogViewer\Contracts\Utilities\Filesystem $filesystem |
|
62
|
|
|
* @param \Arcanedev\LogViewer\Contracts\Utilities\LogLevels $levels |
|
63
|
|
|
*/ |
|
64
|
195 |
|
public function __construct( |
|
65
|
|
|
FactoryContract $factory, |
|
66
|
|
|
FilesystemContract $filesystem, |
|
67
|
|
|
LogLevelsContract $levels |
|
68
|
|
|
) { |
|
69
|
195 |
|
$this->factory = $factory; |
|
70
|
195 |
|
$this->filesystem = $filesystem; |
|
71
|
195 |
|
$this->levels = $levels; |
|
72
|
195 |
|
} |
|
73
|
|
|
|
|
74
|
|
|
/* ----------------------------------------------------------------- |
|
75
|
|
|
| Getters & Setters |
|
76
|
|
|
| ----------------------------------------------------------------- |
|
77
|
|
|
*/ |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Get the log levels. |
|
81
|
|
|
* |
|
82
|
|
|
* @param bool $flip |
|
83
|
|
|
* |
|
84
|
|
|
* @return array |
|
85
|
|
|
*/ |
|
86
|
105 |
|
public function levels($flip = false) |
|
87
|
|
|
{ |
|
88
|
105 |
|
return $this->levels->lists($flip); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Get the translated log levels. |
|
93
|
|
|
* |
|
94
|
|
|
* @param string|null $locale |
|
95
|
|
|
* |
|
96
|
|
|
* @return array |
|
97
|
|
|
*/ |
|
98
|
12 |
|
public function levelsNames($locale = null) |
|
99
|
|
|
{ |
|
100
|
12 |
|
return $this->levels->names($locale); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Set the log storage path. |
|
105
|
|
|
* |
|
106
|
|
|
* @param string $path |
|
107
|
|
|
* |
|
108
|
|
|
* @return self |
|
109
|
|
|
*/ |
|
110
|
6 |
|
public function setPath($path) |
|
111
|
|
|
{ |
|
112
|
6 |
|
$this->factory->setPath($path); |
|
113
|
|
|
|
|
114
|
6 |
|
return $this; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* Get the log pattern. |
|
119
|
|
|
* |
|
120
|
|
|
* @return string |
|
121
|
|
|
*/ |
|
122
|
3 |
|
public function getPattern() |
|
123
|
|
|
{ |
|
124
|
3 |
|
return $this->factory->getPattern(); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* Set the log pattern. |
|
129
|
|
|
* |
|
130
|
|
|
* @param string $date |
|
131
|
|
|
* @param string $prefix |
|
132
|
|
|
* @param string $extension |
|
133
|
|
|
* |
|
134
|
|
|
* @return self |
|
135
|
|
|
*/ |
|
136
|
3 |
|
public function setPattern( |
|
137
|
|
|
$prefix = FilesystemContract::PATTERN_PREFIX, |
|
138
|
|
|
$date = FilesystemContract::PATTERN_DATE, |
|
139
|
|
|
$extension = FilesystemContract::PATTERN_EXTENSION |
|
140
|
|
|
) { |
|
141
|
3 |
|
$this->factory->setPattern($prefix, $date, $extension); |
|
142
|
|
|
|
|
143
|
3 |
|
return $this; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/* ----------------------------------------------------------------- |
|
147
|
|
|
| Main Methods |
|
148
|
|
|
| ----------------------------------------------------------------- |
|
149
|
|
|
*/ |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* Get all logs. |
|
153
|
|
|
* |
|
154
|
|
|
* @return \Arcanedev\LogViewer\Entities\LogCollection |
|
155
|
|
|
*/ |
|
156
|
3 |
|
public function all() |
|
157
|
|
|
{ |
|
158
|
3 |
|
return $this->factory->all(); |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
/** |
|
162
|
|
|
* Paginate all logs. |
|
163
|
|
|
* |
|
164
|
|
|
* @param int $perPage |
|
165
|
|
|
* |
|
166
|
|
|
* @return \Illuminate\Pagination\LengthAwarePaginator |
|
167
|
|
|
*/ |
|
168
|
3 |
|
public function paginate($perPage = 30) |
|
169
|
|
|
{ |
|
170
|
3 |
|
return $this->factory->paginate($perPage); |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* Get a log. |
|
175
|
|
|
* |
|
176
|
|
|
* @param string $date |
|
177
|
|
|
* |
|
178
|
|
|
* @return \Arcanedev\LogViewer\Entities\Log |
|
179
|
|
|
*/ |
|
180
|
15 |
|
public function get($date) |
|
181
|
|
|
{ |
|
182
|
15 |
|
return $this->factory->log($date); |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
/** |
|
186
|
|
|
* Get the log entries. |
|
187
|
|
|
* |
|
188
|
|
|
* @param string $date |
|
189
|
|
|
* @param string $level |
|
190
|
|
|
* |
|
191
|
|
|
* @return \Arcanedev\LogViewer\Entities\LogEntryCollection |
|
192
|
|
|
*/ |
|
193
|
9 |
|
public function entries($date, $level = 'all') |
|
194
|
|
|
{ |
|
195
|
9 |
|
return $this->factory->entries($date, $level); |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
/** |
|
199
|
|
|
* Download a log file. |
|
200
|
|
|
* |
|
201
|
|
|
* @param string $date |
|
202
|
|
|
* @param string|null $filename |
|
203
|
|
|
* @param array $headers |
|
204
|
|
|
* |
|
205
|
|
|
* @return \Symfony\Component\HttpFoundation\BinaryFileResponse |
|
206
|
|
|
*/ |
|
207
|
6 |
|
public function download($date, $filename = null, $headers = []) |
|
208
|
|
|
{ |
|
209
|
6 |
|
if (is_null($filename)) { |
|
210
|
6 |
|
$filename = "laravel-{$date}.log"; |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
6 |
|
$path = $this->filesystem->path($date); |
|
214
|
|
|
|
|
215
|
6 |
|
return response()->download($path, $filename, $headers); |
|
|
|
|
|
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
/** |
|
219
|
|
|
* Get logs statistics. |
|
220
|
|
|
* |
|
221
|
|
|
* @return array |
|
222
|
|
|
*/ |
|
223
|
33 |
|
public function stats() |
|
224
|
|
|
{ |
|
225
|
33 |
|
return $this->factory->stats(); |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
/** |
|
229
|
|
|
* Get logs statistics table. |
|
230
|
|
|
* |
|
231
|
|
|
* @param string|null $locale |
|
232
|
|
|
* |
|
233
|
|
|
* @return \Arcanedev\LogViewer\Tables\StatsTable |
|
234
|
|
|
*/ |
|
235
|
12 |
|
public function statsTable($locale = null) |
|
236
|
|
|
{ |
|
237
|
12 |
|
return $this->factory->statsTable($locale); |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
/** |
|
241
|
|
|
* Delete the log. |
|
242
|
|
|
* |
|
243
|
|
|
* @param string $date |
|
244
|
|
|
* |
|
245
|
|
|
* @return bool |
|
246
|
|
|
*/ |
|
247
|
9 |
|
public function delete($date) |
|
248
|
|
|
{ |
|
249
|
9 |
|
return $this->filesystem->delete($date); |
|
250
|
|
|
} |
|
251
|
|
|
|
|
252
|
|
|
/** |
|
253
|
|
|
* Clear the log files. |
|
254
|
|
|
* |
|
255
|
|
|
* @return bool |
|
256
|
|
|
*/ |
|
257
|
3 |
|
public function clear() |
|
258
|
|
|
{ |
|
259
|
3 |
|
return $this->filesystem->clear(); |
|
260
|
|
|
} |
|
261
|
|
|
|
|
262
|
|
|
/** |
|
263
|
|
|
* Get all valid log files. |
|
264
|
|
|
* |
|
265
|
|
|
* @return array |
|
266
|
|
|
*/ |
|
267
|
3 |
|
public function files() |
|
268
|
|
|
{ |
|
269
|
3 |
|
return $this->filesystem->logs(); |
|
270
|
|
|
} |
|
271
|
|
|
|
|
272
|
|
|
/** |
|
273
|
|
|
* List the log files (only dates). |
|
274
|
|
|
* |
|
275
|
|
|
* @return array |
|
276
|
|
|
*/ |
|
277
|
6 |
|
public function dates() |
|
278
|
|
|
{ |
|
279
|
6 |
|
return $this->factory->dates(); |
|
280
|
|
|
} |
|
281
|
|
|
|
|
282
|
|
|
/** |
|
283
|
|
|
* Get logs count. |
|
284
|
|
|
* |
|
285
|
|
|
* @return int |
|
286
|
|
|
*/ |
|
287
|
6 |
|
public function count() |
|
288
|
|
|
{ |
|
289
|
6 |
|
return $this->factory->count(); |
|
290
|
|
|
} |
|
291
|
|
|
|
|
292
|
|
|
/** |
|
293
|
|
|
* Get entries total from all logs. |
|
294
|
|
|
* |
|
295
|
|
|
* @param string $level |
|
296
|
|
|
* |
|
297
|
|
|
* @return int |
|
298
|
|
|
*/ |
|
299
|
6 |
|
public function total($level = 'all') |
|
300
|
|
|
{ |
|
301
|
6 |
|
return $this->factory->total($level); |
|
302
|
|
|
} |
|
303
|
|
|
|
|
304
|
|
|
/** |
|
305
|
|
|
* Get logs tree. |
|
306
|
|
|
* |
|
307
|
|
|
* @param bool $trans |
|
308
|
|
|
* |
|
309
|
|
|
* @return array |
|
310
|
|
|
*/ |
|
311
|
3 |
|
public function tree($trans = false) |
|
312
|
|
|
{ |
|
313
|
3 |
|
return $this->factory->tree($trans); |
|
314
|
|
|
} |
|
315
|
|
|
|
|
316
|
|
|
/** |
|
317
|
|
|
* Get logs menu. |
|
318
|
|
|
* |
|
319
|
|
|
* @param bool $trans |
|
320
|
|
|
* |
|
321
|
|
|
* @return array |
|
322
|
|
|
*/ |
|
323
|
3 |
|
public function menu($trans = true) |
|
324
|
|
|
{ |
|
325
|
3 |
|
return $this->factory->menu($trans); |
|
326
|
|
|
} |
|
327
|
|
|
|
|
328
|
|
|
/* ----------------------------------------------------------------- |
|
329
|
|
|
| Check Methods |
|
330
|
|
|
| ----------------------------------------------------------------- |
|
331
|
|
|
*/ |
|
332
|
|
|
|
|
333
|
|
|
/** |
|
334
|
|
|
* Determine if the log folder is empty or not. |
|
335
|
|
|
* |
|
336
|
|
|
* @return bool |
|
337
|
|
|
*/ |
|
338
|
3 |
|
public function isEmpty() |
|
339
|
|
|
{ |
|
340
|
3 |
|
return $this->factory->isEmpty(); |
|
341
|
|
|
} |
|
342
|
|
|
|
|
343
|
|
|
/* ----------------------------------------------------------------- |
|
344
|
|
|
| Other Methods |
|
345
|
|
|
| ----------------------------------------------------------------- |
|
346
|
|
|
*/ |
|
347
|
|
|
|
|
348
|
|
|
/** |
|
349
|
|
|
* Get the LogViewer version. |
|
350
|
|
|
* |
|
351
|
|
|
* @return string |
|
352
|
|
|
*/ |
|
353
|
36 |
|
public function version() |
|
354
|
|
|
{ |
|
355
|
36 |
|
return self::VERSION; |
|
356
|
|
|
} |
|
357
|
|
|
} |
|
358
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: