EmailPatterns
10 months ago
EmailTemplates
2 months ago
PersonalizationTags
3 months ago
WCTransactionalEmails
4 weeks ago
BlockEmailRenderer.php
7 months ago
EmailApiController.php
4 weeks ago
Integration.php
4 weeks ago
Logger.php
10 months ago
Package.php
1 year ago
PageRenderer.php
10 months ago
PersonalizationTagManager.php
1 year ago
TransactionalEmailPersonalizer.php
4 months ago
WooContentProcessor.php
2 months ago
Logger.php
158 lines
| 1 | <?php |
| 2 | /** |
| 3 | * This file is part of the WooCommerce package. |
| 4 | * |
| 5 | * @package Automattic\WooCommerce\Internal\EmailEditor |
| 6 | */ |
| 7 | |
| 8 | declare(strict_types = 1); |
| 9 | |
| 10 | namespace Automattic\WooCommerce\Internal\EmailEditor; |
| 11 | |
| 12 | use Automattic\WooCommerce\EmailEditor\Engine\Logger\Email_Editor_Logger_Interface; |
| 13 | use WC_Log_Levels; |
| 14 | |
| 15 | /** |
| 16 | * WooCommerce logger adapter for the email editor. |
| 17 | * |
| 18 | * This class adapts the WooCommerce logger to work with the email editor logging interface. |
| 19 | */ |
| 20 | class Logger implements Email_Editor_Logger_Interface { |
| 21 | /** |
| 22 | * The WooCommerce logger instance. |
| 23 | * |
| 24 | * @var \WC_Logger_Interface |
| 25 | */ |
| 26 | private \WC_Logger_Interface $wc_logger; |
| 27 | |
| 28 | /** |
| 29 | * Constructor. |
| 30 | * |
| 31 | * @param \WC_Logger_Interface $wc_logger The WooCommerce logger instance. |
| 32 | */ |
| 33 | public function __construct( \WC_Logger_Interface $wc_logger ) { |
| 34 | $this->wc_logger = $wc_logger; |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Checks if the log level should be handled. |
| 39 | * |
| 40 | * @param string $level The log level. |
| 41 | * @return bool Whether the log level should be handled. |
| 42 | */ |
| 43 | private function should_handle( string $level ): bool { |
| 44 | /** |
| 45 | * Controls the logging threshold for the email editor. |
| 46 | * |
| 47 | * @param string $threshold The log level threshold. |
| 48 | * |
| 49 | * @since 10.2.0 |
| 50 | */ |
| 51 | $logging_threshold = apply_filters( 'woocommerce_email_editor_logging_threshold', WC_Log_Levels::WARNING ); |
| 52 | |
| 53 | return WC_Log_Levels::get_level_severity( $logging_threshold ) <= WC_Log_Levels::get_level_severity( $level ); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Adds emergency level log message. |
| 58 | * |
| 59 | * @param string $message The log message. |
| 60 | * @param array $context The log context. |
| 61 | * @return void |
| 62 | */ |
| 63 | public function emergency( string $message, array $context = array() ): void { |
| 64 | $this->log( WC_Log_Levels::EMERGENCY, $message, $context ); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Adds alert level log message. |
| 69 | * |
| 70 | * @param string $message The log message. |
| 71 | * @param array $context The log context. |
| 72 | * @return void |
| 73 | */ |
| 74 | public function alert( string $message, array $context = array() ): void { |
| 75 | $this->log( WC_Log_Levels::ALERT, $message, $context ); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Adds critical level log message. |
| 80 | * |
| 81 | * @param string $message The log message. |
| 82 | * @param array $context The log context. |
| 83 | * @return void |
| 84 | */ |
| 85 | public function critical( string $message, array $context = array() ): void { |
| 86 | $this->log( WC_Log_Levels::CRITICAL, $message, $context ); |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Adds error level log message. |
| 91 | * |
| 92 | * @param string $message The log message. |
| 93 | * @param array $context The log context. |
| 94 | * @return void |
| 95 | */ |
| 96 | public function error( string $message, array $context = array() ): void { |
| 97 | $this->log( WC_Log_Levels::ERROR, $message, $context ); |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Adds warning level log message. |
| 102 | * |
| 103 | * @param string $message The log message. |
| 104 | * @param array $context The log context. |
| 105 | * @return void |
| 106 | */ |
| 107 | public function warning( string $message, array $context = array() ): void { |
| 108 | $this->log( WC_Log_Levels::WARNING, $message, $context ); |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Adds notice level log message. |
| 113 | * |
| 114 | * @param string $message The log message. |
| 115 | * @param array $context The log context. |
| 116 | * @return void |
| 117 | */ |
| 118 | public function notice( string $message, array $context = array() ): void { |
| 119 | $this->log( WC_Log_Levels::NOTICE, $message, $context ); |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Adds info level log message. |
| 124 | * |
| 125 | * @param string $message The log message. |
| 126 | * @param array $context The log context. |
| 127 | * @return void |
| 128 | */ |
| 129 | public function info( string $message, array $context = array() ): void { |
| 130 | $this->log( WC_Log_Levels::INFO, $message, $context ); |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Adds debug level log message. |
| 135 | * |
| 136 | * @param string $message The log message. |
| 137 | * @param array $context The log context. |
| 138 | * @return void |
| 139 | */ |
| 140 | public function debug( string $message, array $context = array() ): void { |
| 141 | $this->log( WC_Log_Levels::DEBUG, $message, $context ); |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * Logs with an arbitrary level. |
| 146 | * |
| 147 | * @param string $level The log level. |
| 148 | * @param string $message The log message. |
| 149 | * @param array $context The log context. |
| 150 | * @return void |
| 151 | */ |
| 152 | public function log( string $level, string $message, array $context = array() ): void { |
| 153 | if ( $this->should_handle( $level ) ) { |
| 154 | $this->wc_logger->log( $level, $message, $context ); |
| 155 | } |
| 156 | } |
| 157 | } |
| 158 |