1 | <?php namespace Arcanedev\LogViewer\Entities; |
||
14 | class LogEntry implements Arrayable, Jsonable, JsonSerializable |
||
15 | { |
||
16 | /* ------------------------------------------------------------------------------------------------ |
||
17 | | Properties |
||
18 | | ------------------------------------------------------------------------------------------------ |
||
19 | */ |
||
20 | /** @var string */ |
||
21 | public $env; |
||
22 | |||
23 | /** @var string */ |
||
24 | public $level; |
||
25 | |||
26 | /** @var \Carbon\Carbon */ |
||
27 | public $datetime; |
||
28 | |||
29 | /** @var string */ |
||
30 | public $header; |
||
31 | |||
32 | /** @var string */ |
||
33 | public $stack; |
||
34 | |||
35 | /* ------------------------------------------------------------------------------------------------ |
||
36 | | Constructor |
||
37 | | ------------------------------------------------------------------------------------------------ |
||
38 | */ |
||
39 | /** |
||
40 | * Construct the log entry instance. |
||
41 | * |
||
42 | * @param string $level |
||
43 | * @param string $header |
||
44 | * @param string $stack |
||
45 | */ |
||
46 | 864 | public function __construct($level, $header, $stack) |
|
52 | |||
53 | /* ------------------------------------------------------------------------------------------------ |
||
54 | | Getters & Setters |
||
55 | | ------------------------------------------------------------------------------------------------ |
||
56 | */ |
||
57 | /** |
||
58 | * Set the entry level. |
||
59 | * |
||
60 | * @param string $level |
||
61 | * |
||
62 | * @return self |
||
63 | */ |
||
64 | 864 | private function setLevel($level) |
|
70 | |||
71 | /** |
||
72 | * Set the entry header. |
||
73 | * |
||
74 | * @param string $header |
||
75 | * |
||
76 | * @return self |
||
77 | */ |
||
78 | 864 | private function setHeader($header) |
|
93 | |||
94 | /** |
||
95 | * Set entry environment. |
||
96 | * |
||
97 | * @param string $env |
||
98 | * |
||
99 | * @return self |
||
100 | */ |
||
101 | 864 | private function setEnv($env) |
|
107 | |||
108 | /** |
||
109 | * Set the entry date time. |
||
110 | * |
||
111 | * @param string $datetime |
||
112 | * |
||
113 | * @return \Arcanedev\LogViewer\Entities\LogEntry |
||
114 | */ |
||
115 | 864 | private function setDatetime($datetime) |
|
116 | { |
||
117 | 864 | $this->datetime = Carbon::createFromFormat('Y-m-d H:i:s', $datetime); |
|
118 | 864 | ||
119 | return $this; |
||
120 | 648 | } |
|
121 | |||
122 | 864 | /** |
|
123 | * Set the entry stack. |
||
124 | * |
||
125 | * @param string $stack |
||
126 | * |
||
127 | * @return self |
||
128 | */ |
||
129 | private function setStack($stack) |
||
135 | |||
136 | 864 | /** |
|
137 | * Get translated level name with icon. |
||
138 | * |
||
139 | * @return string |
||
140 | */ |
||
141 | public function level() |
||
142 | { |
||
143 | return $this->icon().' '.$this->name(); |
||
144 | 24 | } |
|
145 | |||
146 | 24 | /** |
|
147 | * Get translated level name. |
||
148 | * |
||
149 | * @return string |
||
150 | */ |
||
151 | public function name() |
||
152 | { |
||
153 | return log_levels()->get($this->level); |
||
154 | 24 | } |
|
155 | |||
156 | 24 | /** |
|
157 | * Get level icon. |
||
158 | * |
||
159 | * @return string |
||
160 | */ |
||
161 | public function icon() |
||
165 | |||
166 | 24 | /** |
|
167 | * Get the entry stack. |
||
168 | * |
||
169 | * @return string |
||
170 | */ |
||
171 | public function stack() |
||
175 | |||
176 | /* ------------------------------------------------------------------------------------------------ |
||
177 | | Check Functions |
||
178 | | ------------------------------------------------------------------------------------------------ |
||
179 | */ |
||
180 | 96 | /** |
|
181 | * Check if same log level. |
||
182 | 96 | * |
|
183 | * @param string $level |
||
184 | * |
||
185 | * @return bool |
||
186 | */ |
||
187 | public function isSameLevel($level) |
||
191 | |||
192 | /* ------------------------------------------------------------------------------------------------ |
||
193 | | Convert Functions |
||
194 | 24 | | ------------------------------------------------------------------------------------------------ |
|
195 | */ |
||
196 | /** |
||
197 | 24 | * Get the log entry as an array. |
|
198 | 24 | * |
|
199 | 24 | * @return array |
|
200 | 24 | */ |
|
201 | 18 | public function toArray() |
|
210 | |||
211 | 12 | /** |
|
212 | * Convert the log entry to its JSON representation. |
||
213 | 12 | * |
|
214 | * @param int $options |
||
215 | * |
||
216 | * @return string |
||
217 | */ |
||
218 | public function toJson($options = 0) |
||
222 | |||
223 | 12 | /** |
|
224 | * Serialize the log entry object to json data. |
||
225 | * |
||
226 | * @return array |
||
227 | */ |
||
228 | public function jsonSerialize() |
||
232 | |||
233 | /* ------------------------------------------------------------------------------------------------ |
||
234 | | Check Functions |
||
235 | 24 | | ------------------------------------------------------------------------------------------------ |
|
236 | */ |
||
237 | 24 | /** |
|
238 | * Check if the entry has a stack. |
||
239 | * |
||
240 | * @return bool |
||
241 | */ |
||
242 | public function hasStack() |
||
246 | |||
247 | /* ------------------------------------------------------------------------------------------------ |
||
248 | | Other Functions |
||
249 | | ------------------------------------------------------------------------------------------------ |
||
250 | */ |
||
251 | 864 | /** |
|
252 | * Clean the entry header. |
||
253 | 864 | * |
|
254 | * @param string $header |
||
255 | * |
||
256 | * @return string |
||
257 | */ |
||
258 | private function cleanHeader($header) |
||
262 | |||
263 | 864 | /** |
|
264 | * Extract datetime from the header. |
||
265 | 864 | * |
|
266 | * @param string $header |
||
267 | * |
||
268 | * @return string |
||
269 | */ |
||
270 | private function extractDatetime($header) |
||
274 | } |
||
275 |