Skip to content

Commit 94b0b67

Browse files
committed
chore: 🔊 Clean up ingestion-related log entries
1 parent 5a34f44 commit 94b0b67

2 files changed

Lines changed: 41 additions & 18 deletions

File tree

‎modules/ppcp-store-sync/src/Ingestion/ProductFilter.php‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,17 @@ public function mark_processed( WC_Product $product, string $log_info = '' ): vo
106106
$product->update_meta_data( self::META_KEY, (string) time() );
107107
$product->save_meta_data();
108108

109+
$context = array();
110+
if ( '' !== $log_info ) {
111+
$context['log_info'] = $log_info;
112+
}
113+
109114
$this->logger->debug(
110115
sprintf(
111-
'Agentic ProductFilter: marked product %d processed',
116+
'[ProductFilter] Marked product %d processed',
112117
$product->get_id()
113118
),
114-
array( 'info' => $log_info )
119+
$context
115120
);
116121
}
117122

@@ -140,6 +145,6 @@ public function invalidate_all(): void {
140145
*/
141146
do_action( 'woocommerce_paypal_payments_store_sync_eligibility_invalidated' );
142147

143-
$this->logger->info( 'Agentic ProductFilter: invalidated all processed markers' );
148+
$this->logger->info( '[ProductFilter] Invalidated all processed markers' );
144149
}
145150
}

‎modules/ppcp-store-sync/src/Ingestion/SyncJob.php‎

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ public function __construct(
5858
*/
5959
public function execute(): void {
6060
$this->logger->info(
61-
sprintf( 'Agentic Sync Job %s: Started', $this->batch_id )
61+
'[Sync] Started',
62+
$this->build_log_context()
6263
);
6364

6465
// Transform products into DTOs.
@@ -75,7 +76,8 @@ public function execute(): void {
7576

7677
if ( empty( $products ) ) {
7778
$this->logger->info(
78-
sprintf( 'Agentic Sync Job %s: No products', $this->batch_id )
79+
'[Sync] No products',
80+
$this->build_log_context()
7981
);
8082

8183
$this->fire_completed_action( 'empty', 0, 0, 0 );
@@ -104,7 +106,7 @@ public function execute(): void {
104106
)
105107
);
106108

107-
$this->logger->debug( "Start Sync {$this->batch_id}...", $body );
109+
$this->logger->debug( '[Sync] Started...', $this->build_log_context( $body ) );
108110

109111
if ( is_wp_error( $response ) ) {
110112
// Log the error message and throw an Exception.
@@ -195,11 +197,10 @@ private function handle_successful_response( string $response_body, array $paylo
195197

196198
$this->logger->info(
197199
sprintf(
198-
'Agentic Sync Job %s: Successfully synced %d products',
199-
$this->batch_id,
200+
'[Sync] Successfully synced %d products',
200201
count( $this->product_ids )
201202
),
202-
$response_data
203+
$this->build_log_context( $response_data )
203204
);
204205

205206
$contains_errors = false === ( $response_data['success'] ?? false );
@@ -279,11 +280,8 @@ private function extract_product_errors( string $error_message, array $payload_p
279280
*/
280281
private function mark_products_by_validation_result( array $validation_errors ): void {
281282
$this->logger->warning(
282-
sprintf(
283-
'Agentic Sync Job %s: Validation errors',
284-
$this->batch_id
285-
),
286-
$validation_errors
283+
'[Sync] Validation errors',
284+
$this->build_log_context( $validation_errors )
287285
);
288286

289287
foreach ( $validation_errors as $product_id => $error_message ) {
@@ -304,10 +302,12 @@ private function mark_products_by_validation_result( array $validation_errors ):
304302
*/
305303
private function handle_api_error( array $product_ids, string $error_message ): void {
306304
$this->logger->warning(
307-
sprintf( 'Agentic Sync Job %s: API Error - %s', $this->batch_id, $error_message ),
308-
array(
309-
'product_count' => count( $product_ids ),
310-
'product_ids' => $product_ids,
305+
sprintf( '[Sync] API Error - %s', $error_message ),
306+
$this->build_log_context(
307+
array(
308+
'product_count' => count( $product_ids ),
309+
'product_ids' => $product_ids,
310+
)
311311
)
312312
);
313313

@@ -384,4 +384,22 @@ private function mark_products_synced( array $product_ids ): void {
384384
$this->mark_product_synced( $product_id );
385385
}
386386
}
387+
388+
/**
389+
* @param mixed $context The log data - an array or any other value to log.
390+
* @return array
391+
*/
392+
private function build_log_context( $context = array() ): array {
393+
$log_context = array( 'job' => $this->batch_id );
394+
395+
if ( ! is_array( $context ) ) {
396+
if ( null === $context ) {
397+
$context = array();
398+
} else {
399+
$context = array( 'raw' => $context );
400+
}
401+
}
402+
403+
return array_merge( $log_context, $context );
404+
}
387405
}

0 commit comments

Comments
 (0)