diff --git a/includes/API/Plugin/Settings/Handler.php b/includes/API/Plugin/Settings/Handler.php index 259f44a4e..97963cd2a 100644 --- a/includes/API/Plugin/Settings/Handler.php +++ b/includes/API/Plugin/Settings/Handler.php @@ -13,6 +13,7 @@ use WooCommerce\Facebook\API\Plugin\AbstractRESTEndpoint; use WooCommerce\Facebook\API\Plugin\Settings\Update\Request as UpdateRequest; use WooCommerce\Facebook\API\Plugin\Settings\Uninstall\Request as UninstallRequest; +use WooCommerce\Facebook\Framework\Logger; defined( 'ABSPATH' ) || exit; @@ -283,12 +284,17 @@ private function maybe_trigger_feed_uploads( bool $should_trigger_products_and_s if ( facebook_for_woocommerce()->get_integration()->allow_full_batch_api_sync() ) { facebook_for_woocommerce()->get_products_sync_handler()->create_or_update_all_products(); } else { - \WC_Facebookcommerce_Utils::log_to_meta( + Logger::log( 'Initial full product sync disabled by filter hook `facebook_for_woocommerce_allow_full_batch_api_sync`', [ 'flow_name' => 'product_sync', 'flow_step' => 'initial_sync', - ] + ], + array( + 'should_send_log_to_meta' => true, + 'should_save_log_in_woocommerce' => true, + 'woocommerce_log_level' => \WC_Log_Levels::DEBUG, + ) ); } } diff --git a/includes/Feed/FeedUploadUtils.php b/includes/Feed/FeedUploadUtils.php index 8bad96899..798c8eb29 100644 --- a/includes/Feed/FeedUploadUtils.php +++ b/includes/Feed/FeedUploadUtils.php @@ -11,6 +11,7 @@ namespace WooCommerce\Facebook\Feed; use WC_Coupon; +use WooCommerce\Facebook\Framework\Logger; /** * Class containing util functions related to various feed uploads. @@ -88,7 +89,7 @@ public static function get_ratings_and_reviews_data( array $query_args ): array 'product.productIdentifiers.skus' => "['" . implode( "','", $product_skus ) . "']", ); } catch ( \Exception $e ) { - \WC_Facebookcommerce_Utils::log_to_meta( + Logger::log( 'Exception while trying to map product review data for feed', array( 'flow_name' => self::RATINGS_AND_REVIEWS_SYNC_LOGGING_FLOW_NAME, @@ -96,6 +97,11 @@ public static function get_ratings_and_reviews_data( array $query_args ): array 'extra_data' => [ 'exception_message' => $e->getMessage(), ], + ), + array( + 'should_send_log_to_meta' => true, + 'should_save_log_in_woocommerce' => true, + 'woocommerce_log_level' => \WC_Log_Levels::ERROR, ) ); continue; @@ -152,13 +158,18 @@ public static function get_coupons_data( array $query_args ): array { $value_type = self::VALUE_TYPE_FIXED_AMOUNT; $fixed_amount_off = $coupon->get_amount(); // TODO we may want to pass in optional currency code for multinational support } else { - \WC_Facebookcommerce_Utils::log_to_meta( + Logger::log( 'Unknown discount type encountered during feed processing', array( 'promotion_id' => $coupon_post->ID, 'extra_data' => [ 'discount_type' => $woo_discount_type ], 'flow_name' => self::PROMO_SYNC_LOGGING_FLOW_NAME, 'flow_step' => 'map_discount_type', + ), + array( + 'should_send_log_to_meta' => true, + 'should_save_log_in_woocommerce' => true, + 'woocommerce_log_level' => \WC_Log_Levels::WARNING, ) ); continue; @@ -250,7 +261,7 @@ public static function get_coupons_data( array $query_args ): array { $coupons_data[] = $data; } catch ( \Exception $e ) { - \WC_Facebookcommerce_Utils::log_to_meta( + Logger::log( 'Exception while trying to get coupon data for feed', array( 'promotion_id' => $coupon_post->ID, @@ -260,6 +271,11 @@ public static function get_coupons_data( array $query_args ): array { ], 'flow_name' => self::PROMO_SYNC_LOGGING_FLOW_NAME, 'flow_step' => 'map_coupon_data', + ), + array( + 'should_send_log_to_meta' => true, + 'should_save_log_in_woocommerce' => true, + 'woocommerce_log_level' => \WC_Log_Levels::ERROR, ) ); continue; @@ -354,11 +370,13 @@ private static function get_target_filter( return ''; } - // Return the JSON representation. It should look something like: - // {"and":[ - // {"or":[{"retailer_id":{"eq":"retailer_id_1"}},{"retailer_id":{"eq":"retailer_id_2"}}]}, - // {"and":[{"retailer_id":{"neq":"retailer_id_3"}},{"retailer_id":{"neq":"retailer_id_4"}}]} - // ]} + /** + * Return the JSON representation. It should look something like: + * {"and":[ + * {"or":[{"retailer_id":{"eq":"retailer_id_1"}},{"retailer_id":{"eq":"retailer_id_2"}}]}, + * {"and":[{"retailer_id":{"neq":"retailer_id_3"}},{"retailer_id":{"neq":"retailer_id_4"}}]} + * ]} + */ return wp_json_encode( $final_filter ); } diff --git a/includes/Feed/ShippingProfiles/ShippingProfilesFeed.php b/includes/Feed/ShippingProfiles/ShippingProfilesFeed.php index 4dd3e5161..268f21c47 100644 --- a/includes/Feed/ShippingProfiles/ShippingProfilesFeed.php +++ b/includes/Feed/ShippingProfiles/ShippingProfilesFeed.php @@ -13,6 +13,7 @@ use Automattic\WooCommerce\ActionSchedulerJobFramework\Proxies\ActionScheduler; use WC_Shipping_Zones; +use WooCommerce\Facebook\Framework\Logger; /** * Ratings and Reviews Feed class @@ -294,7 +295,7 @@ private static function get_flat_rate_shipping_method_data( array $zone, array $ } private static function log_map_shipping_method_issue_to_meta( array $zone, array $shipping_method, string $message, string $flow_step ): void { - \WC_Facebookcommerce_Utils::log_to_meta( + Logger::log( $message, array( 'flow_name' => FeedUploadUtils::SHIPPING_PROFILES_SYNC_LOGGING_FLOW_NAME, @@ -304,6 +305,11 @@ private static function log_map_shipping_method_issue_to_meta( array $zone, arra 'zone_name' => $zone['zone_name'], 'method_id' => $shipping_method['instance_id'], ], + ), + array( + 'should_send_log_to_meta' => true, + 'should_save_log_in_woocommerce' => true, + 'woocommerce_log_level' => \WC_Log_Levels::DEBUG, ) ); } diff --git a/includes/Products/Feed.php b/includes/Products/Feed.php index 8aa92479d..f0692293b 100644 --- a/includes/Products/Feed.php +++ b/includes/Products/Feed.php @@ -18,6 +18,7 @@ use WooCommerce\Facebook\Framework\Helper; use WooCommerce\Facebook\Utilities\Heartbeat; use WooCommerce\Facebook\Framework\Plugin\Exception as PluginException; +use WooCommerce\Facebook\Framework\Logger; /** * The main product feed handler. @@ -179,11 +180,16 @@ public function schedule_feed_generation() { } elseif ( ! $store_allows_feed ) { $message = 'Store does not allow feed.'; } - WC_Facebookcommerce_Utils::log_to_meta( + Logger::log( sprintf( 'Product feed scheduling failed: %s', $message ), array( 'flow_name' => 'product_feed', 'flow_step' => 'schedule_feed_generation', + ), + array( + 'should_send_log_to_meta' => true, + 'should_save_log_in_woocommerce' => true, + 'woocommerce_log_level' => \WC_Log_Levels::DEBUG, ) ); return;