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0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / includes / class-wc-logger.php
woocommerce / includes Last commit date
abstracts 2 years ago admin 2 years ago blocks 5 years ago cli 2 years ago customizer 3 years ago data-stores 2 years ago emails 2 years ago export 2 years ago gateways 2 years ago import 2 years ago integrations 2 years ago interfaces 3 years ago legacy 2 years ago libraries 3 years ago log-handlers 2 years ago payment-tokens 5 years ago queue 4 years ago react-admin 2 years ago rest-api 2 years ago shipping 2 years ago shortcodes 2 years ago theme-support 2 years ago tracks 2 years ago traits 5 years ago walkers 5 years ago wccom-site 2 years ago widgets 3 years ago class-wc-ajax.php 2 years ago class-wc-api.php 4 years ago class-wc-auth.php 4 years ago class-wc-autoloader.php 5 years ago class-wc-background-emailer.php 5 years ago class-wc-background-updater.php 5 years ago class-wc-breadcrumb.php 5 years ago class-wc-cache-helper.php 3 years ago class-wc-cart-fees.php 2 years ago class-wc-cart-session.php 2 years ago class-wc-cart-totals.php 2 years ago class-wc-cart.php 2 years ago class-wc-checkout.php 2 years ago class-wc-cli.php 3 years ago class-wc-comments.php 3 years ago class-wc-countries.php 2 years ago class-wc-coupon.php 2 years ago class-wc-customer-download-log.php 5 years ago class-wc-customer-download.php 4 years ago class-wc-customer.php 2 years ago class-wc-data-exception.php 8 years ago class-wc-data-store.php 3 years ago class-wc-datetime.php 4 years ago class-wc-deprecated-action-hooks.php 8 years ago class-wc-deprecated-filter-hooks.php 3 years ago class-wc-discounts.php 2 years ago class-wc-download-handler.php 3 years ago class-wc-emails.php 2 years ago class-wc-embed.php 5 years ago class-wc-form-handler.php 2 years ago class-wc-frontend-scripts.php 2 years ago class-wc-geo-ip.php 4 years ago class-wc-geolite-integration.php 6 years ago class-wc-geolocation.php 3 years ago class-wc-https.php 2 years ago class-wc-install.php 2 years ago class-wc-integrations.php 5 years ago class-wc-log-levels.php 2 years ago class-wc-logger.php 2 years ago class-wc-meta-data.php 4 years ago class-wc-order-factory.php 3 years ago class-wc-order-item-coupon.php 4 years ago class-wc-order-item-fee.php 4 years ago class-wc-order-item-meta.php 4 years ago class-wc-order-item-product.php 2 years ago class-wc-order-item-shipping.php 4 years ago class-wc-order-item-tax.php 4 years ago class-wc-order-item.php 4 years ago class-wc-order-query.php 4 years ago class-wc-order-refund.php 2 years ago class-wc-order.php 2 years ago class-wc-payment-gateways.php 2 years ago class-wc-payment-tokens.php 3 years ago class-wc-post-data.php 3 years ago class-wc-post-types.php 3 years ago class-wc-privacy-background-process.php 5 years ago class-wc-privacy-erasers.php 4 years ago class-wc-privacy-exporters.php 4 years ago class-wc-privacy.php 2 years ago class-wc-product-attribute.php 4 years ago class-wc-product-download.php 2 years ago class-wc-product-external.php 5 years ago class-wc-product-factory.php 5 years ago class-wc-product-grouped.php 8 years ago class-wc-product-query.php 5 years ago class-wc-product-simple.php 2 years ago class-wc-product-variable.php 3 years ago class-wc-product-variation.php 4 years ago class-wc-query.php 3 years ago class-wc-rate-limiter.php 4 years ago class-wc-regenerate-images-request.php 3 years ago class-wc-regenerate-images.php 3 years ago class-wc-register-wp-admin-settings.php 4 years ago class-wc-rest-authentication.php 3 years ago class-wc-rest-exception.php 5 years ago class-wc-session-handler.php 2 years ago class-wc-shipping-rate.php 3 years ago class-wc-shipping-zone.php 5 years ago class-wc-shipping-zones.php 5 years ago class-wc-shipping.php 4 years ago class-wc-shortcodes.php 2 years ago class-wc-structured-data.php 3 years ago class-wc-tax.php 2 years ago class-wc-template-loader.php 2 years ago class-wc-tracker.php 2 years ago class-wc-validation.php 3 years ago class-wc-webhook.php 2 years ago class-woocommerce.php 2 years ago wc-account-functions.php 2 years ago wc-attribute-functions.php 3 years ago wc-cart-functions.php 2 years ago wc-conditional-functions.php 2 years ago wc-core-functions.php 2 years ago wc-coupon-functions.php 3 years ago wc-deprecated-functions.php 2 years ago wc-formatting-functions.php 2 years ago wc-notice-functions.php 2 years ago wc-order-functions.php 2 years ago wc-order-item-functions.php 3 years ago wc-page-functions.php 2 years ago wc-product-functions.php 2 years ago wc-rest-functions.php 3 years ago wc-stock-functions.php 3 years ago wc-template-functions.php 2 years ago wc-template-hooks.php 5 years ago wc-term-functions.php 3 years ago wc-update-functions.php 2 years ago wc-user-functions.php 2 years ago wc-webhook-functions.php 4 years ago wc-widget-functions.php 5 years ago
class-wc-logger.php
323 lines
1 <?php
2 /**
3 * Provides logging capabilities for debugging purposes.
4 *
5 * @class WC_Logger
6 * @version 2.0.0
7 * @package WooCommerce\Classes
8 */
9
10 use Automattic\WooCommerce\Utilities\LoggingUtil;
11
12 defined( 'ABSPATH' ) || exit;
13
14 /**
15 * WC_Logger class.
16 */
17 class WC_Logger implements WC_Logger_Interface {
18 /**
19 * Stores registered log handlers.
20 *
21 * @var array
22 */
23 protected $handlers;
24
25 /**
26 * Minimum log level this handler will process.
27 *
28 * @var int Integer representation of minimum log level to handle.
29 */
30 protected $threshold;
31
32 /**
33 * Constructor for the logger.
34 *
35 * @param array $handlers Optional. Array of log handlers. If $handlers is not provided, the filter 'woocommerce_register_log_handlers' will be used to define the handlers. If $handlers is provided, the filter will not be applied and the handlers will be used directly.
36 * @param string $threshold Optional. Define an explicit threshold. May be configured via WC_LOG_THRESHOLD. By default, all logs will be processed.
37 */
38 public function __construct( $handlers = null, $threshold = null ) {
39 if ( null === $handlers ) {
40 $default_handler = LoggingUtil::get_default_handler();
41 $handler_instance = new $default_handler();
42
43 /**
44 * Filter the list of log handler class instances that will run whenever a log entry is added.
45 *
46 * @param WC_Log_Handler_Interface[]
47 *
48 * @since 3.0.0
49 */
50 $handlers = apply_filters( 'woocommerce_register_log_handlers', array( $handler_instance ) );
51 }
52
53 $register_handlers = array();
54
55 if ( ! empty( $handlers ) && is_array( $handlers ) ) {
56 foreach ( $handlers as $handler ) {
57 if ( $handler instanceof WC_Log_Handler_Interface ) {
58 $register_handlers[] = $handler;
59 } else {
60 wc_doing_it_wrong(
61 __METHOD__,
62 sprintf(
63 /* translators: 1: class name 2: WC_Log_Handler_Interface */
64 __( 'The provided handler %1$s does not implement %2$s.', 'woocommerce' ),
65 '<code>' . esc_html( is_object( $handler ) ? get_class( $handler ) : $handler ) . '</code>',
66 '<code>WC_Log_Handler_Interface</code>'
67 ),
68 '3.0'
69 );
70 }
71 }
72 }
73
74 if ( ! WC_Log_Levels::is_valid_level( $threshold ) ) {
75 $threshold = LoggingUtil::get_level_threshold();
76 }
77
78 $this->handlers = $register_handlers;
79 $this->threshold = WC_Log_Levels::get_level_severity( $threshold );
80 }
81
82 /**
83 * Determine whether to handle or ignore log.
84 *
85 * @param string $level emergency|alert|critical|error|warning|notice|info|debug.
86 * @return bool True if the log should be handled.
87 */
88 protected function should_handle( $level ) {
89 if ( ! LoggingUtil::logging_is_enabled() ) {
90 return false;
91 }
92
93 if ( null === $this->threshold ) {
94 return true;
95 }
96
97 return $this->threshold <= WC_Log_Levels::get_level_severity( $level );
98 }
99
100 /**
101 * Add a log entry.
102 *
103 * This is not the preferred method for adding log messages. Please use log() or any one of
104 * the level methods (debug(), info(), etc.). This method may be deprecated in the future.
105 *
106 * @param string $handle File handle.
107 * @param string $message Message to log.
108 * @param string $level Logging level.
109 * @return bool
110 */
111 public function add( $handle, $message, $level = WC_Log_Levels::NOTICE ) {
112 $message = apply_filters( 'woocommerce_logger_add_message', $message, $handle );
113 $this->log(
114 $level,
115 $message,
116 array(
117 'source' => $handle,
118 '_legacy' => true,
119 )
120 );
121 wc_do_deprecated_action( 'woocommerce_log_add', array( $handle, $message ), '3.0', 'This action has been deprecated with no alternative.' );
122 return true;
123 }
124
125 /**
126 * Add a log entry.
127 *
128 * @param string $level One of the following:
129 * 'emergency': System is unusable.
130 * 'alert': Action must be taken immediately.
131 * 'critical': Critical conditions.
132 * 'error': Error conditions.
133 * 'warning': Warning conditions.
134 * 'notice': Normal but significant condition.
135 * 'info': Informational messages.
136 * 'debug': Debug-level messages.
137 * @param string $message Log message.
138 * @param array $context Optional. Additional information for log handlers.
139 *
140 * @return void
141 */
142 public function log( $level, $message, $context = array() ) {
143 if ( ! WC_Log_Levels::is_valid_level( $level ) ) {
144 /* translators: 1: WC_Logger::log 2: level */
145 wc_doing_it_wrong( __METHOD__, sprintf( __( '%1$s was called with an invalid level "%2$s".', 'woocommerce' ), '<code>WC_Logger::log</code>', $level ), '3.0' );
146 }
147
148 if ( $this->should_handle( $level ) ) {
149 $timestamp = time();
150
151 foreach ( $this->handlers as $handler ) {
152 /**
153 * Filter the logging message. Returning null will prevent logging from occurring since 5.3.
154 *
155 * @since 3.1
156 * @param string $message Log message.
157 * @param string $level One of: emergency, alert, critical, error, warning, notice, info, or debug.
158 * @param array $context Additional information for log handlers.
159 * @param object $handler The handler object, such as WC_Log_Handler_File. Available since 5.3.
160 */
161 $message = apply_filters( 'woocommerce_logger_log_message', $message, $level, $context, $handler );
162
163 if ( null !== $message ) {
164 $handler->handle( $timestamp, $level, $message, $context );
165 }
166 }
167 }
168 }
169
170 /**
171 * Adds an emergency level message.
172 *
173 * System is unusable.
174 *
175 * @see WC_Logger::log
176 *
177 * @param string $message Message to log.
178 * @param array $context Log context.
179 */
180 public function emergency( $message, $context = array() ) {
181 $this->log( WC_Log_Levels::EMERGENCY, $message, $context );
182 }
183
184 /**
185 * Adds an alert level message.
186 *
187 * Action must be taken immediately.
188 * Example: Entire website down, database unavailable, etc.
189 *
190 * @see WC_Logger::log
191 *
192 * @param string $message Message to log.
193 * @param array $context Log context.
194 */
195 public function alert( $message, $context = array() ) {
196 $this->log( WC_Log_Levels::ALERT, $message, $context );
197 }
198
199 /**
200 * Adds a critical level message.
201 *
202 * Critical conditions.
203 * Example: Application component unavailable, unexpected exception.
204 *
205 * @see WC_Logger::log
206 *
207 * @param string $message Message to log.
208 * @param array $context Log context.
209 */
210 public function critical( $message, $context = array() ) {
211 $this->log( WC_Log_Levels::CRITICAL, $message, $context );
212 }
213
214 /**
215 * Adds an error level message.
216 *
217 * Runtime errors that do not require immediate action but should typically be logged
218 * and monitored.
219 *
220 * @see WC_Logger::log
221 *
222 * @param string $message Message to log.
223 * @param array $context Log context.
224 */
225 public function error( $message, $context = array() ) {
226 $this->log( WC_Log_Levels::ERROR, $message, $context );
227 }
228
229 /**
230 * Adds a warning level message.
231 *
232 * Exceptional occurrences that are not errors.
233 *
234 * Example: Use of deprecated APIs, poor use of an API, undesirable things that are not
235 * necessarily wrong.
236 *
237 * @see WC_Logger::log
238 *
239 * @param string $message Message to log.
240 * @param array $context Log context.
241 */
242 public function warning( $message, $context = array() ) {
243 $this->log( WC_Log_Levels::WARNING, $message, $context );
244 }
245
246 /**
247 * Adds a notice level message.
248 *
249 * Normal but significant events.
250 *
251 * @see WC_Logger::log
252 *
253 * @param string $message Message to log.
254 * @param array $context Log context.
255 */
256 public function notice( $message, $context = array() ) {
257 $this->log( WC_Log_Levels::NOTICE, $message, $context );
258 }
259
260 /**
261 * Adds a info level message.
262 *
263 * Interesting events.
264 * Example: User logs in, SQL logs.
265 *
266 * @see WC_Logger::log
267 *
268 * @param string $message Message to log.
269 * @param array $context Log context.
270 */
271 public function info( $message, $context = array() ) {
272 $this->log( WC_Log_Levels::INFO, $message, $context );
273 }
274
275 /**
276 * Adds a debug level message.
277 *
278 * Detailed debug information.
279 *
280 * @see WC_Logger::log
281 *
282 * @param string $message Message to log.
283 * @param array $context Log context.
284 */
285 public function debug( $message, $context = array() ) {
286 $this->log( WC_Log_Levels::DEBUG, $message, $context );
287 }
288
289 /**
290 * Clear entries for a chosen file/source.
291 *
292 * @param string $source Source/handle to clear.
293 * @return bool
294 */
295 public function clear( $source = '' ) {
296 if ( ! $source ) {
297 return false;
298 }
299 foreach ( $this->handlers as $handler ) {
300 if ( is_callable( array( $handler, 'clear' ) ) ) {
301 $handler->clear( $source );
302 }
303 }
304 return true;
305 }
306
307 /**
308 * Clear all logs older than a defined number of days. Defaults to 30 days.
309 *
310 * @return void
311 */
312 public function clear_expired_logs() {
313 $days = LoggingUtil::get_retention_period();
314 $timestamp = strtotime( "-{$days} days" );
315
316 foreach ( $this->handlers as $handler ) {
317 if ( is_callable( array( $handler, 'delete_logs_before_timestamp' ) ) ) {
318 $handler->delete_logs_before_timestamp( $timestamp );
319 }
320 }
321 }
322 }
323