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