Automattic\WooCommerce\Internal\Logging
RemoteLogger::should_handle
Determine whether to handle or ignore log.
Method of the class: RemoteLogger{}
No Hooks.
Returns
true|false
. True if the log should be handled.
Usage
// protected - for code of main (parent) or child class $result = $this->should_handle( $level, $message, $context );
- $level(string) (required)
- emergency|alert|critical|error|warning|notice|info|debug.
- $message(string) (required)
- Log message to be recorded.
- $context(array) (required)
- Additional information for log handlers.
RemoteLogger::should_handle() RemoteLogger::should handle code WC 9.9.4
protected function should_handle( $level, $message, $context ) { // Ignore logs that are not opted in for remote logging. if ( ! isset( $context['remote-logging'] ) || false === $context['remote-logging'] ) { return false; } if ( ! $this->is_remote_logging_allowed() ) { return false; } if ( $this->is_third_party_error( (string) $message, (array) $context ) ) { return false; } // Record fatal error stats. if ( WC_Log_Levels::get_level_severity( $level ) >= WC_Log_Levels::get_level_severity( WC_Log_Levels::CRITICAL ) ) { try { $mc_stats = wc_get_container()->get( McStats::class ); $mc_stats->add( 'error', 'critical-errors' ); $mc_stats->do_server_side_stats(); } catch ( \Throwable $e ) { error_log( 'Warning: Failed to record fatal error stats: ' . $e->getMessage() ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log } } if ( WC_Rate_Limiter::retried_too_soon( self::RATE_LIMIT_ID ) ) { // Log locally that the remote logging is throttled. SafeGlobalFunctionProxy::wc_get_logger()->warning( 'Remote logging throttled.', array( 'source' => 'remote-logging' ) ); return false; } return true; }