PluginProbe
DecaLog / 4.4.0
DecaLog v4.4.0
3.0.2 3.1.0 3.10.0 3.2.0 3.3.0 3.4.0 3.4.1 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.6.3 3.7.0 3.7.1 3.8.0 3.9.0 3.9.1 4.0.0 4.1.0 4.2.0 4.3.0 4.3.1 4.4.0 4.5.0 All 75 releases
decalog / includes / api / class-v5logger.php

class-v5logger.php in DecaLog 4.4.0, at includes/api/class-v5logger.php

372 lines 16.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * DecaLog PSR-3 logger definition.
4 *
5 * @package API
6 * @author Pierre Lannoy <https://pierre.lannoy.fr/>.
7 * @since 1.3.0
8 */
9
10 namespace Decalog;
11
12 use Decalog\Plugin\Feature\DLogger;
13 use Psr\Log\LoggerInterface;
14 use Psr\Log\LogLevel;
15
16 if ( 3 === \decalog_get_psr_log_version() ) {
17
18 /**
19 * DecaLog PSR-3 logger class.
20 *
21 * This class defines all code necessary to log events with DecaLog.
22 *
23 * @package API
24 * @author Pierre Lannoy <https://pierre.lannoy.fr/>.
25 * @since 1.3.0
26 */
27 class Logger implements LoggerInterface {
28
29 /**
30 * The "true" DLogger instance.
31 *
32 * @since 1.3.0
33 * @var \Decalog\Plugin\Feature\DLogger $logger Maintains the internal DLogger instance.
34 */
35 private $logger = null;
36
37 /**
38 * Initialize the class and set its properties.
39 *
40 * @param string $class The class identifier, must be a value in ['plugin', 'theme', 'library'].
41 * @param string $name Optional. The name of the component that will trigger events.
42 * @param string $version Optional. The version of the component that will trigger events.
43 * @since 1.3.0
44 */
45 public function __construct( $class, $name = null, $version = null ) {
46 $this->logger = new DLogger( $class, $name, $version, null, true );
47 }
48
49 /**
50 * Logs a panic condition. WordPress is unusable.
51 *
52 * @param string|\Stringable $message The message to log.
53 * @param mixed[] $context Optional. The context of the event.
54 * FYI, DecaLog has its own context-aware logging system. The only element
55 * of context that you can pass to DecaLog is a numerical error code
56 * ($context['code']). All other element of context will be removed.
57 * @return void
58 * @since 4.0.0
59 */
60 public function emergency( string|\Stringable $message, array $context = [] ): void {
61 $this->logger->emergency( (string) $message, array_key_exists( 'code', $context ) ? (int) $context['code'] : 0 );
62 }
63
64 /**
65 * Logs a major operating error that undoubtedly affects the operations.
66 * It requires immediate investigation and corrective treatment.
67 *
68 * @param string|\Stringable $message The message to log.
69 * @param mixed[] $context Optional. The context of the event.
70 * FYI, DecaLog has its own context-aware logging system. The only element
71 * of context that you can pass to DecaLog is a numerical error code
72 * ($context['code']). All other element of context will be removed.
73 *
74 * @return void
75 * @since 4.0.0
76 */
77 public function alert( string|\Stringable $message, array $context = [] ): void {
78 $this->logger->alert( (string) $message, array_key_exists( 'code', $context ) ? (int) $context['code'] : 0 );
79 }
80
81 /**
82 * Logs an operating error that undoubtedly affects the operations.
83 * It requires investigation and corrective treatment.
84 *
85 * @param string|\Stringable $message The message to log.
86 * @param mixed[] $context Optional. The context of the event.
87 * FYI, DecaLog has its own context-aware logging system. The only element
88 * of context that you can pass to DecaLog is a numerical error code
89 * ($context['code']). All other element of context will be removed.
90 *
91 * @return void
92 * @since 4.0.0
93 */
94 public function critical( string|\Stringable $message, array $context = [] ): void {
95 $this->logger->critical( (string) $message, array_key_exists( 'code', $context ) ? (int) $context['code'] : 0 );
96 }
97
98 /**
99 * Logs a minor operating error that may affects the operations.
100 * It requires investigation and preventive treatment.
101 *
102 * @param string|\Stringable $message The message to log.
103 * @param mixed[] $context Optional. The context of the event.
104 * FYI, DecaLog has its own context-aware logging system. The only element
105 * of context that you can pass to DecaLog is a numerical error code
106 * ($context['code']). All other element of context will be removed.
107 *
108 * @return void
109 * @since 4.0.0
110 */
111 public function error( string|\Stringable $message, array $context = [] ): void {
112 $this->logger->error( (string) $message, array_key_exists( 'code', $context ) ? (int) $context['code'] : 0 );
113 }
114
115 /**
116 * Logs a significant condition indicating a situation that may lead to an error if recurring or if no action is taken.
117 * Does not usually affect the operations.
118 *
119 * @param string|\Stringable $message The message to log.
120 * @param mixed[] $context Optional. The context of the event.
121 * FYI, DecaLog has its own context-aware logging system. The only element
122 * of context that you can pass to DecaLog is a numerical error code
123 * ($context['code']). All other element of context will be removed.
124 *
125 * @return void
126 * @since 4.0.0
127 */
128 public function warning( string|\Stringable $message, array $context = [] ): void {
129 $this->logger->warning( (string) $message, array_key_exists( 'code', $context ) ? (int) $context['code'] : 0 );
130 }
131
132 /**
133 * Logs a normal but significant condition.
134 *
135 * @param string|\Stringable $message The message to log.
136 * @param mixed[] $context Optional. The context of the event.
137 * FYI, DecaLog has its own context-aware logging system. The only element
138 * of context that you can pass to DecaLog is a numerical error code
139 * ($context['code']). All other element of context will be removed.
140 *
141 * @return void
142 * @since 4.0.0
143 */
144 public function notice( string|\Stringable $message, array $context = [] ): void {
145 $this->logger->notice( (string) $message, array_key_exists( 'code', $context ) ? (int) $context['code'] : 0 );
146 }
147
148 /**
149 * Logs a standard information.
150 *
151 * @param string|\Stringable $message The message to log.
152 * @param mixed[] $context Optional. The context of the event.
153 * FYI, DecaLog has its own context-aware logging system. The only element
154 * of context that you can pass to DecaLog is a numerical error code
155 * ($context['code']). All other element of context will be removed.
156 *
157 * @return void
158 * @since 4.0.0
159 */
160 public function info( string|\Stringable $message, array $context = [] ): void {
161 $this->logger->info( (string) $message, array_key_exists( 'code', $context ) ? (int) $context['code'] : 0 );
162 }
163
164 /**
165 * Logs an information for developers and testers.
166 * Only used for events related to application/system debugging.
167 *
168 * @param string|\Stringable $message The message to log.
169 * @param mixed[] $context Optional. The context of the event.
170 * FYI, DecaLog has its own context-aware logging system. The only element
171 * of context that you can pass to DecaLog is a numerical error code
172 * ($context['code']). All other element of context will be removed.
173 *
174 * @return void
175 * @since 4.0.0
176 */
177 public function debug( string|\Stringable $message, array $context = [] ): void {
178 $this->logger->debug( (string) $message, array_key_exists( 'code', $context ) ? (int) $context['code'] : 0 );
179 }
180
181 /**
182 * Logs an information with an arbitrary level.
183 *
184 * @param LogLevel $level The level of the message to log.
185 * @param string|\Stringable $message The message to log.
186 * @param mixed[] $context Optional. The context of the event.
187 * FYI, DecaLog has its own context-aware logging system. The only element
188 * of context that you can pass to DecaLog is a numerical error code
189 * ($context['code']). All other element of context will be removed.
190 *
191 * @return void
192 * @since 4.0.0
193 */
194 public function log( $level, string|\Stringable $message, array $context = [] ): void {
195 $this->logger->log( $level, (string) $message, array_key_exists( 'code', $context ) ? (int) $context['code'] : 0 );
196 }
197 }
198 } else {
199
200 /**
201 * DecaLog PSR-3 logger class.
202 *
203 * This class defines all code necessary to log events with DecaLog.
204 *
205 * @package API
206 * @author Pierre Lannoy <https://pierre.lannoy.fr/>.
207 * @since 1.3.0
208 */
209 class Logger implements LoggerInterface {
210
211 /**
212 * The "true" DLogger instance.
213 *
214 * @since 1.3.0
215 * @var \Decalog\Plugin\Feature\DLogger $logger Maintains the internal DLogger instance.
216 */
217 private $logger = null;
218
219 /**
220 * Initialize the class and set its properties.
221 *
222 * @param string $class The class identifier, must be a value in ['plugin', 'theme'].
223 * @param string $name Optional. The name of the component that will trigger events.
224 * @param string $version Optional. The version of the component that will trigger events.
225 * @since 1.3.0
226 */
227 public function __construct( $class, $name = null, $version = null ) {
228 $this->logger = new DLogger( $class, $name, $version, null, true );
229 }
230
231 /**
232 * Logs a panic condition. WordPress is unusable.
233 *
234 * @param string $message The message to log.
235 * @param array $context Optional. The context of the event.
236 * FYI, DecaLog has its own context-aware logging system. The only element of context
237 * that you can pass to DecaLog is a numerical error code ($context['code']). All other
238 * element of context will be removed.
239 * @return void
240 * @since 1.3.0
241 */
242 public function emergency( $message, $context = [] ) {
243 $this->logger->emergency( (string) $message, array_key_exists( 'code', $context ) ? (int) $context['code'] : 0 );
244 }
245
246 /**
247 * Logs a major operating error that undoubtedly affects the operations.
248 * It requires immediate investigation and corrective treatment.
249 *
250 * @param string $message The message to log.
251 * @param array $context Optional. The context of the event.
252 * FYI, DecaLog has its own context-aware logging system. The only element of context
253 * that you can pass to DecaLog is a numerical error code ($context['code']). All other
254 * element of context will be removed.
255 * @return void
256 * @since 1.3.0
257 */
258 public function alert( $message, $context = [] ) {
259 $this->logger->alert( (string) $message, array_key_exists( 'code', $context ) ? (int) $context['code'] : 0 );
260 }
261
262 /**
263 * Logs an operating error that undoubtedly affects the operations.
264 * It requires investigation and corrective treatment.
265 *
266 * @param string $message The message to log.
267 * @param array $context Optional. The context of the event.
268 * FYI, DecaLog has its own context-aware logging system. The only element of context
269 * that you can pass to DecaLog is a numerical error code ($context['code']). All other
270 * element of context will be removed.
271 * @return void
272 * @since 1.3.0
273 */
274 public function critical( $message, $context = [] ) {
275 $this->logger->critical( (string) $message, array_key_exists( 'code', $context ) ? (int) $context['code'] : 0 );
276 }
277
278 /**
279 * Logs a minor operating error that may affects the operations.
280 * It requires investigation and preventive treatment.
281 *
282 * @param string $message The message to log.
283 * @param array $context Optional. The context of the event.
284 * FYI, DecaLog has its own context-aware logging system. The only element of context
285 * that you can pass to DecaLog is a numerical error code ($context['code']). All other
286 * element of context will be removed.
287 * @return void
288 * @since 1.3.0
289 */
290 public function error( $message, $context = [] ) {
291 $this->logger->error( (string) $message, array_key_exists( 'code', $context ) ? (int) $context['code'] : 0 );
292 }
293
294 /**
295 * Logs a significant condition indicating a situation that may lead to an error if recurring or if no action is taken.
296 * Does not usually affect the operations.
297 *
298 * @param string $message The message to log.
299 * @param array $context Optional. The context of the event.
300 * FYI, DecaLog has its own context-aware logging system. The only element of context
301 * that you can pass to DecaLog is a numerical error code ($context['code']). All other
302 * element of context will be removed.
303 * @return void
304 * @since 1.3.0
305 */
306 public function warning( $message, $context = [] ) {
307 $this->logger->warning( (string) $message, array_key_exists( 'code', $context ) ? (int) $context['code'] : 0 );
308 }
309
310 /**
311 * Logs a normal but significant condition.
312 *
313 * @param string $message The message to log.
314 * @param array $context Optional. The context of the event.
315 * FYI, DecaLog has its own context-aware logging system. The only element of context
316 * that you can pass to DecaLog is a numerical error code ($context['code']). All other
317 * element of context will be removed.
318 * @return void
319 * @since 1.3.0
320 */
321 public function notice( $message, $context = [] ) {
322 $this->logger->notice( (string) $message, array_key_exists( 'code', $context ) ? (int) $context['code'] : 0 );
323 }
324
325 /**
326 * Logs a standard information.
327 *
328 * @param string $message The message to log.
329 * @param array $context Optional. The context of the event.
330 * FYI, DecaLog has its own context-aware logging system. The only element of context
331 * that you can pass to DecaLog is a numerical error code ($context['code']). All other
332 * element of context will be removed.
333 * @return void
334 * @since 1.3.0
335 */
336 public function info( $message, $context = [] ) {
337 $this->logger->info( (string) $message, array_key_exists( 'code', $context ) ? (int) $context['code'] : 0 );
338 }
339
340 /**
341 * Logs an information for developers and testers.
342 * Only used for events related to application/system debugging.
343 *
344 * @param string $message The message to log.
345 * @param array $context Optional. The context of the event.
346 * FYI, DecaLog has its own context-aware logging system. The only element of context
347 * that you can pass to DecaLog is a numerical error code ($context['code']). All other
348 * element of context will be removed.
349 * @return void
350 * @since 1.3.0
351 */
352 public function debug( $message, $context = [] ) {
353 $this->logger->debug( (string) $message, array_key_exists( 'code', $context ) ? (int) $context['code'] : 0 );
354 }
355
356 /**
357 * Logs an information with an arbitrary level.
358 *
359 * @param LogLevel $level The level of the message to log.
360 * @param string $message Optional. The message to log.
361 * @param array $context The context of the event.
362 * FYI, DecaLog has its own context-aware logging system. The only element of context
363 * that you can pass to DecaLog is a numerical error code ($context['code']). All other
364 * element of context will be removed.
365 * @return void
366 * @since 1.3.0
367 */
368 public function log( $level, $message, $context = [] ) {
369 $this->logger->log( $level, (string) $message, array_key_exists( 'code', $context ) ? (int) $context['code'] : 0 );
370 }
371 }
372 }