Automattic\WooCommerce\Internal\BatchProcessing

BatchProcessingController::log_error()protectedWC 1.0

Log an error that happened while processing a batch.

Method of the class: BatchProcessingController{}

Hooks from the method

Return

null. Nothing (null).

Usage

// protected - for code of main (parent) or child class
$result = $this->log_error( $error, $batch_processor, $batch ) : void;
$error(\Exception) (required)
Exception object to log.
$batch_processor(BatchProcessorInterface) (required)
Batch processor instance.
$batch(array) (required)
Batch that was being processed.

BatchProcessingController::log_error() code WC 8.7.0

protected function log_error( \Exception $error, BatchProcessorInterface $batch_processor, array $batch ) : void {
	$batch_detail_string = '';
	// Log only first and last, as the entire batch may be too big.
	if ( count( $batch ) > 0 ) {
		$batch_detail_string = "\n" . wp_json_encode(
			array(
				'batch_start' => $batch[0],
				'batch_end'   => end( $batch ),
			),
			JSON_PRETTY_PRINT
		);
	}
	$error_message = "Error processing batch for {$batch_processor->get_name()}: {$error->getMessage()}" . $batch_detail_string;

	/**
	 * Filters the error message for a batch processing.
	 *
	 * @param string $error_message The error message that will be logged.
	 * @param \Exception $error The exception that was thrown by the processor.
	 * @param BatchProcessorInterface $batch_processor The processor that threw the exception.
	 * @param array $batch The batch that was being processed.
	 * @return string The actual error message that will be logged.
	 *
	 * @since 6.8.0
	 */
	$error_message = apply_filters( 'wc_batch_processing_log_message', $error_message, $error, $batch_processor, $batch );

	$this->logger->error( $error_message, array( 'exception' => $error ) );
}