1 | <?php namespace Arcanedev\LogViewer\Entities; |
||
14 | class LogEntry implements Arrayable, Jsonable, JsonSerializable |
||
15 | { |
||
16 | /* ----------------------------------------------------------------- |
||
17 | | Properties |
||
18 | | ----------------------------------------------------------------- |
||
19 | */ |
||
20 | |||
21 | /** @var string */ |
||
22 | public $env; |
||
23 | |||
24 | /** @var string */ |
||
25 | public $level; |
||
26 | |||
27 | /** @var \Carbon\Carbon */ |
||
28 | public $datetime; |
||
29 | |||
30 | /** @var string */ |
||
31 | public $header; |
||
32 | |||
33 | /** @var string */ |
||
34 | public $stack; |
||
35 | |||
36 | /** @var array */ |
||
37 | public $context = []; |
||
38 | |||
39 | /* ----------------------------------------------------------------- |
||
40 | | Constructor |
||
41 | | ----------------------------------------------------------------- |
||
42 | */ |
||
43 | |||
44 | /** |
||
45 | * Construct the log entry instance. |
||
46 | * |
||
47 | * @param string $level |
||
48 | * @param string $header |
||
49 | * @param string|null $stack |
||
50 | */ |
||
51 | 189 | public function __construct($level, $header, $stack = null) |
|
57 | |||
58 | /* ----------------------------------------------------------------- |
||
59 | | Getters & Setters |
||
60 | | ----------------------------------------------------------------- |
||
61 | */ |
||
62 | |||
63 | /** |
||
64 | * Set the entry level. |
||
65 | * |
||
66 | * @param string $level |
||
67 | * |
||
68 | * @return self |
||
69 | */ |
||
70 | 189 | private function setLevel($level) |
|
76 | |||
77 | /** |
||
78 | * Set the entry header. |
||
79 | * |
||
80 | * @param string $header |
||
81 | * |
||
82 | * @return self |
||
83 | */ |
||
84 | 189 | private function setHeader($header) |
|
94 | |||
95 | /** |
||
96 | * Set the context. |
||
97 | * |
||
98 | * @param array $context |
||
99 | * |
||
100 | * @return $this |
||
101 | */ |
||
102 | 3 | private function setContext(array $context) |
|
108 | |||
109 | /** |
||
110 | * Set entry environment. |
||
111 | * |
||
112 | * @param string $env |
||
113 | * |
||
114 | * @return self |
||
115 | */ |
||
116 | 189 | private function setEnv($env) |
|
122 | |||
123 | /** |
||
124 | * Set the entry date time. |
||
125 | * |
||
126 | * @param string $datetime |
||
127 | * |
||
128 | * @return \Arcanedev\LogViewer\Entities\LogEntry |
||
129 | */ |
||
130 | 189 | private function setDatetime($datetime) |
|
136 | |||
137 | /** |
||
138 | * Set the entry stack. |
||
139 | * |
||
140 | * @param string $stack |
||
141 | * |
||
142 | * @return self |
||
143 | */ |
||
144 | 189 | private function setStack($stack) |
|
150 | |||
151 | /** |
||
152 | * Get translated level name with icon. |
||
153 | * |
||
154 | * @return string |
||
155 | */ |
||
156 | 18 | public function level() |
|
160 | |||
161 | /** |
||
162 | * Get translated level name. |
||
163 | * |
||
164 | * @return string |
||
165 | */ |
||
166 | 18 | public function name() |
|
170 | |||
171 | /** |
||
172 | * Get level icon. |
||
173 | * |
||
174 | * @return \Illuminate\Support\HtmlString |
||
175 | */ |
||
176 | 18 | public function icon() |
|
180 | |||
181 | /** |
||
182 | * Get the entry stack. |
||
183 | * |
||
184 | * @return string |
||
185 | */ |
||
186 | 21 | public function stack() |
|
190 | |||
191 | /** |
||
192 | * Get the entry context as json pretty print. |
||
193 | * |
||
194 | * @return string |
||
195 | */ |
||
196 | 3 | public function context() |
|
200 | |||
201 | /* ----------------------------------------------------------------- |
||
202 | | Check Methods |
||
203 | | ----------------------------------------------------------------- |
||
204 | */ |
||
205 | |||
206 | /** |
||
207 | * Check if same log level. |
||
208 | * |
||
209 | * @param string $level |
||
210 | * |
||
211 | * @return bool |
||
212 | */ |
||
213 | 27 | public function isSameLevel($level) |
|
217 | |||
218 | /* ----------------------------------------------------------------- |
||
219 | | Convert Methods |
||
220 | | ----------------------------------------------------------------- |
||
221 | */ |
||
222 | |||
223 | /** |
||
224 | * Get the log entry as an array. |
||
225 | * |
||
226 | * @return array |
||
227 | */ |
||
228 | 6 | public function toArray() |
|
237 | |||
238 | /** |
||
239 | * Convert the log entry to its JSON representation. |
||
240 | * |
||
241 | * @param int $options |
||
242 | * |
||
243 | * @return string |
||
244 | */ |
||
245 | 3 | public function toJson($options = 0) |
|
249 | |||
250 | /** |
||
251 | * Serialize the log entry object to json data. |
||
252 | * |
||
253 | * @return array |
||
254 | */ |
||
255 | 3 | public function jsonSerialize() |
|
259 | |||
260 | /* ----------------------------------------------------------------- |
||
261 | | Check Methods |
||
262 | | ----------------------------------------------------------------- |
||
263 | */ |
||
264 | |||
265 | /** |
||
266 | * Check if the entry has a stack. |
||
267 | * |
||
268 | * @return bool |
||
269 | */ |
||
270 | 18 | public function hasStack() |
|
274 | |||
275 | /** |
||
276 | * Check if the entry has a context. |
||
277 | * |
||
278 | * @return bool |
||
279 | */ |
||
280 | 24 | public function hasContext() |
|
284 | |||
285 | /* ----------------------------------------------------------------- |
||
286 | | Other Methods |
||
287 | | ----------------------------------------------------------------- |
||
288 | */ |
||
289 | |||
290 | /** |
||
291 | * Clean the entry header. |
||
292 | * |
||
293 | * @param string $header |
||
294 | * |
||
295 | * @return string |
||
296 | */ |
||
297 | 189 | private function cleanHeader($header) |
|
317 | |||
318 | /** |
||
319 | * Extract datetime from the header. |
||
320 | * |
||
321 | * @param string $header |
||
322 | * |
||
323 | * @return string |
||
324 | */ |
||
325 | 189 | private function extractDatetime($header) |
|
329 | } |
||
330 |