1 | <?php namespace Arcanedev\LogViewer; |
||
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) |
|
112 | |||
113 | /** |
||
114 | * Get the log pattern. |
||
115 | * |
||
116 | * @return string |
||
117 | */ |
||
118 | 12 | public function getPattern() |
|
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( |
|
141 | |||
142 | /* ------------------------------------------------------------------------------------------------ |
||
143 | | Main Functions |
||
144 | | ------------------------------------------------------------------------------------------------ |
||
145 | */ |
||
146 | /** |
||
147 | * Get all logs. |
||
148 | * |
||
149 | * @return Entities\LogCollection |
||
150 | */ |
||
151 | 12 | public function all() |
|
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) |
|
167 | |||
168 | /** |
||
169 | * Get a log. |
||
170 | * |
||
171 | * @param string $date |
||
172 | * |
||
173 | * @return Entities\Log |
||
174 | */ |
||
175 | 60 | public function get($date) |
|
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') |
|
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 = []) |
|
212 | |||
213 | /** |
||
214 | * Get logs statistics. |
||
215 | * |
||
216 | * @return array |
||
217 | */ |
||
218 | 96 | public function stats() |
|
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) |
|
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) |
|
248 | |||
249 | /** |
||
250 | * Get all valid log files. |
||
251 | * |
||
252 | * @return array |
||
253 | */ |
||
254 | 12 | public function files() |
|
258 | |||
259 | /** |
||
260 | * List the log files (only dates). |
||
261 | * |
||
262 | * @return array |
||
263 | */ |
||
264 | 24 | public function dates() |
|
268 | |||
269 | /** |
||
270 | * Get logs count. |
||
271 | * |
||
272 | * @return int |
||
273 | */ |
||
274 | 12 | public function count() |
|
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') |
|
290 | |||
291 | /** |
||
292 | * Get logs tree. |
||
293 | * |
||
294 | * @param bool|false $trans |
||
295 | * |
||
296 | * @return array |
||
297 | */ |
||
298 | 12 | public function tree($trans = false) |
|
302 | |||
303 | /** |
||
304 | * Get logs menu. |
||
305 | * |
||
306 | * @param bool|true $trans |
||
307 | * |
||
308 | * @return array |
||
309 | */ |
||
310 | 12 | public function menu($trans = true) |
|
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() |
|
328 | |||
329 | /* ------------------------------------------------------------------------------------------------ |
||
330 | | Other Functions |
||
331 | | ------------------------------------------------------------------------------------------------ |
||
332 | */ |
||
333 | /** |
||
334 | * Get the LogViewer version. |
||
335 | * |
||
336 | * @return string |
||
337 | */ |
||
338 | 132 | public function version() |
|
342 | } |
||
343 |