PluginProbe
Image Optimizer – Compress Images and Convert to WebP or AVIF / 1.7.4
Image Optimizer – Compress Images and Convert to WebP or AVIF v1.7.4
1.7.7 1.7.6 1.7.5 1.7.4 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 All 33 releases
image-optimization / vendor / elementor / wp-one-package / src / Logger.php

Logger.php in Image Optimizer – Compress Images and Convert to WebP or AVIF 1.7.4, at vendor/elementor/wp-one-package/src/Logger.php

75 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ElementorOne;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit; // Exit if accessed directly.
7 }
8
9 /**
10 * Class Logger
11 */
12 class Logger {
13
14 public const LEVEL_ERROR = 'error';
15 public const LEVEL_WARN = 'warn';
16 public const LEVEL_INFO = 'info';
17
18 /**
19 * @var string Prefix for log messages (e.g., app name)
20 */
21 private string $prefix;
22
23 /**
24 * Constructor
25 *
26 * @param string $prefix Prefix for log messages (e.g., 'Elementor One', 'Elementor AI')
27 */
28 public function __construct( string $prefix ) {
29 $this->prefix = $prefix;
30 }
31
32 /**
33 * Log a message
34 *
35 * @param string $log_level Log level
36 * @param mixed $message Message to log
37 * @return void
38 */
39 private function log( string $log_level, $message ): void {
40 $backtrace = debug_backtrace(); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_debug_backtrace
41
42 $class = $backtrace[2]['class'] ?? null;
43 $type = $backtrace[2]['type'] ?? null;
44 $function = $backtrace[2]['function'];
45
46 if ( $class ) {
47 $message = '[' . $this->prefix . ']: ' . $log_level . ' in ' . "$class$type$function()" . ': ' . $message;
48 } else {
49 $message = '[' . $this->prefix . ']: ' . $log_level . ' in ' . "$function()" . ': ' . $message;
50 }
51
52 error_log( $message ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
53 }
54
55 /**
56 * Log an error message
57 *
58 * @param mixed $message Message to log
59 * @return void
60 */
61 public function error( $message ): void {
62 $this->log( self::LEVEL_ERROR, $message );
63 }
64
65 /**
66 * Log an info message
67 *
68 * @param mixed $message Message to log
69 * @return void
70 */
71 public function info( $message ): void {
72 $this->log( self::LEVEL_INFO, $message );
73 }
74 }
75