mailpoet
/
vendor
/
woocommerce
/
email-editor
/
src
/
Engine
/
Logger
/
class-default-email-editor-logger.php
class-default-email-editor-logger.php
11 months ago
class-email-editor-logger-interface.php
11 months ago
class-email-editor-logger.php
11 months ago
index.php
11 months ago
class-default-email-editor-logger.php
67 lines
| 1 | <?php |
| 2 | declare(strict_types = 1); |
| 3 | namespace Automattic\WooCommerce\EmailEditor\Engine\Logger; |
| 4 | if (!defined('ABSPATH')) exit; |
| 5 | class Default_Email_Editor_Logger implements Email_Editor_Logger_Interface { |
| 6 | public const EMERGENCY = 'emergency'; |
| 7 | public const ALERT = 'alert'; |
| 8 | public const CRITICAL = 'critical'; |
| 9 | public const ERROR = 'error'; |
| 10 | public const WARNING = 'warning'; |
| 11 | public const NOTICE = 'notice'; |
| 12 | public const INFO = 'info'; |
| 13 | public const DEBUG = 'debug'; |
| 14 | private $log_file; |
| 15 | public function __construct() { |
| 16 | if ( defined( 'WP_DEBUG_LOG' ) ) { |
| 17 | if ( true === WP_DEBUG_LOG ) { |
| 18 | $this->log_file = WP_CONTENT_DIR . '/debug.log'; |
| 19 | } elseif ( is_string( WP_DEBUG_LOG ) && ! empty( WP_DEBUG_LOG ) ) { |
| 20 | $this->log_file = WP_DEBUG_LOG; |
| 21 | } else { |
| 22 | $this->log_file = ''; |
| 23 | } |
| 24 | } else { |
| 25 | $this->log_file = ''; |
| 26 | } |
| 27 | } |
| 28 | public function emergency( string $message, array $context = array() ): void { |
| 29 | $this->log( self::EMERGENCY, $message, $context ); |
| 30 | } |
| 31 | public function alert( string $message, array $context = array() ): void { |
| 32 | $this->log( self::ALERT, $message, $context ); |
| 33 | } |
| 34 | public function critical( string $message, array $context = array() ): void { |
| 35 | $this->log( self::CRITICAL, $message, $context ); |
| 36 | } |
| 37 | public function error( string $message, array $context = array() ): void { |
| 38 | $this->log( self::ERROR, $message, $context ); |
| 39 | } |
| 40 | public function warning( string $message, array $context = array() ): void { |
| 41 | $this->log( self::WARNING, $message, $context ); |
| 42 | } |
| 43 | public function notice( string $message, array $context = array() ): void { |
| 44 | $this->log( self::NOTICE, $message, $context ); |
| 45 | } |
| 46 | public function info( string $message, array $context = array() ): void { |
| 47 | $this->log( self::INFO, $message, $context ); |
| 48 | } |
| 49 | public function debug( string $message, array $context = array() ): void { |
| 50 | $this->log( self::DEBUG, $message, $context ); |
| 51 | } |
| 52 | public function log( string $level, string $message, array $context = array() ): void { |
| 53 | if ( ! $this->log_file ) { |
| 54 | return; |
| 55 | } |
| 56 | $entry = sprintf( |
| 57 | '[%s] %s: %s %s', |
| 58 | gmdate( 'Y-m-d H:i:s' ), |
| 59 | strtoupper( $level ), |
| 60 | $message, |
| 61 | ! empty( $context ) ? wp_json_encode( $context ) : '' |
| 62 | ); |
| 63 | // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- This is a logging class, error_log is the intended functionality. |
| 64 | error_log( $entry . PHP_EOL, 3, $this->log_file ); |
| 65 | } |
| 66 | } |
| 67 |