diff --git a/includes/ExternalVersionUpdate/Update.php b/includes/ExternalVersionUpdate/Update.php index 0f08e34b7..78b9f124e 100644 --- a/includes/ExternalVersionUpdate/Update.php +++ b/includes/ExternalVersionUpdate/Update.php @@ -15,6 +15,7 @@ use Exception; use WC_Facebookcommerce_Utils; use WooCommerce\Facebook\Utilities\Heartbeat; +use WooCommerce\Facebook\Framework\Logger; /** * Facebook for WooCommerce External Plugin Version Update. @@ -90,7 +91,15 @@ public function send_new_version_to_facebook_server() { } return update_option( self::LATEST_VERSION_SENT, WC_Facebookcommerce_Utils::PLUGIN_VERSION ); } catch ( Exception $e ) { - WC_Facebookcommerce_Utils::log_with_debug_mode_enabled( $e->getMessage() ); + Logger::log( + $e->getMessage(), + [], + array( + 'should_send_log_to_meta' => false, + 'should_save_log_in_woocommerce' => true, + 'woocommerce_log_level' => \WC_Log_Levels::ERROR, + ) + ); // If the request fails, we should retry it in the next heartbeat. return false; } diff --git a/includes/Products/Feed.php b/includes/Products/Feed.php index f0692293b..dc2d33407 100644 --- a/includes/Products/Feed.php +++ b/includes/Products/Feed.php @@ -82,7 +82,15 @@ private function add_hooks() { * @throws PluginException If the feed secret is invalid, file is not readable, or other errors occur. */ public function handle_feed_data_request() { - \WC_Facebookcommerce_Utils::log_with_debug_mode_enabled( 'Facebook is requesting the product feed.' ); + Logger::log( + 'Facebook is requesting the product feed.', + [], + array( + 'should_send_log_to_meta' => false, + 'should_save_log_in_woocommerce' => true, + 'woocommerce_log_level' => \WC_Log_Levels::DEBUG, + ) + ); facebook_for_woocommerce()->get_tracker()->track_feed_file_requested(); $feed_handler = new \WC_Facebook_Product_Feed(); @@ -120,7 +128,15 @@ public function handle_feed_data_request() { // fpassthru might be disabled in some hosts (like Flywheel) if ( $this->is_fpassthru_disabled() || ! @fpassthru( $file ) ) { - \WC_Facebookcommerce_Utils::log_with_debug_mode_enabled( 'fpassthru is disabled: getting file contents' ); + Logger::log( + 'fpassthru is disabled: getting file contents', + [], + array( + 'should_send_log_to_meta' => false, + 'should_save_log_in_woocommerce' => true, + 'woocommerce_log_level' => \WC_Log_Levels::DEBUG, + ) + ); $contents = @stream_get_contents( $file ); if ( ! $contents ) { throw new PluginException( 'Could not get feed file contents.', 500 ); @@ -128,7 +144,15 @@ public function handle_feed_data_request() { echo $contents; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } } catch ( \Exception $exception ) { - \WC_Facebookcommerce_Utils::log_with_debug_mode_enabled( 'Could not serve product feed. ' . $exception->getMessage() . ' (' . $exception->getCode() . ')' ); + Logger::log( + 'Could not serve product feed. ' . $exception->getMessage() . ' (' . $exception->getCode() . ')', + [], + array( + 'should_send_log_to_meta' => false, + 'should_save_log_in_woocommerce' => true, + 'woocommerce_log_level' => \WC_Log_Levels::ERROR, + ) + ); status_header( $exception->getCode() ); } exit; @@ -189,7 +213,7 @@ public function schedule_feed_generation() { array( 'should_send_log_to_meta' => true, 'should_save_log_in_woocommerce' => true, - 'woocommerce_log_level' => \WC_Log_Levels::DEBUG, + 'woocommerce_log_level' => \WC_Log_Levels::WARNING, ) ); return; @@ -218,7 +242,15 @@ public function schedule_feed_generation() { public function send_request_to_upload_feed() { $feed_id = self::retrieve_or_create_integration_feed_id(); if ( empty( $feed_id ) ) { - WC_Facebookcommerce_Utils::log_with_debug_mode_enabled( 'Feed: integration feed ID is null or empty, feed will not be uploaded.' ); + Logger::log( + 'Feed: integration feed ID is null or empty, feed will not be uploaded.', + [], + array( + 'should_send_log_to_meta' => false, + 'should_save_log_in_woocommerce' => true, + 'woocommerce_log_level' => \WC_Log_Levels::WARNING, + ) + ); return; } @@ -245,7 +277,15 @@ public function retrieve_or_create_integration_feed_id() { $feed_id = self::request_and_filter_integration_feed_id(); if ( $feed_id ) { facebook_for_woocommerce()->get_integration()->update_feed_id( $feed_id ); - WC_Facebookcommerce_Utils::log_with_debug_mode_enabled( 'Feed: feed_id = ' . $feed_id . ', queried and selected from Meta API.' ); + Logger::log( + 'Feed: feed_id = ' . $feed_id . ', queried and selected from Meta API.', + [], + array( + 'should_send_log_to_meta' => false, + 'should_save_log_in_woocommerce' => true, + 'woocommerce_log_level' => \WC_Log_Levels::DEBUG, + ) + ); return $feed_id; } @@ -253,7 +293,15 @@ public function retrieve_or_create_integration_feed_id() { $feed_id = self::create_feed_id(); if ( $feed_id ) { facebook_for_woocommerce()->get_integration()->update_feed_id( $feed_id ); - WC_Facebookcommerce_Utils::log_with_debug_mode_enabled( 'Feed: feed_id = ' . $feed_id . ', created a new feed via Meta API.' ); + Logger::log( + 'Feed: feed_id = ' . $feed_id . ', created a new feed via Meta API.', + [], + array( + 'should_send_log_to_meta' => false, + 'should_save_log_in_woocommerce' => true, + 'woocommerce_log_level' => \WC_Log_Levels::DEBUG, + ) + ); return $feed_id; } @@ -278,7 +326,15 @@ private function request_and_filter_integration_feed_id() { $feed_nodes = facebook_for_woocommerce()->get_api()->read_feeds( $catalog_id )->data; } catch ( Exception $e ) { $message = sprintf( 'There was an error trying to get feed nodes for catalog: %s', $e->getMessage() ); - WC_Facebookcommerce_Utils::log_with_debug_mode_enabled( $message ); + Logger::log( + $message, + [], + array( + 'should_send_log_to_meta' => false, + 'should_save_log_in_woocommerce' => true, + 'woocommerce_log_level' => \WC_Log_Levels::ERROR, + ) + ); return ''; } @@ -298,7 +354,15 @@ private function request_and_filter_integration_feed_id() { $feed_metadata = facebook_for_woocommerce()->get_api()->read_feed( $feed['id'] ); } catch ( Exception $e ) { $message = sprintf( 'There was an error trying to get feed metadata: %s', $e->getMessage() ); - WC_Facebookcommerce_Utils::log_with_debug_mode_enabled( $message ); + Logger::log( + $message, + [], + array( + 'should_send_log_to_meta' => false, + 'should_save_log_in_woocommerce' => true, + 'woocommerce_log_level' => \WC_Log_Levels::ERROR, + ) + ); continue; }