Automattic\WooCommerce\Internal\BatchProcessing
BatchProcessingController::log_error
Log an error that happened while processing a batch.
Method of the class: BatchProcessingController{}
Hooks from the method
Returns
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() BatchProcessingController::log error code WC 10.7.0
protected function log_error( \Exception $error, BatchProcessorInterface $batch_processor, array $batch ): void {
$error_message = "Error processing batch for {$batch_processor->get_name()}: {$error->getMessage()}";
$error_context = array(
'exception' => $error,
'source' => 'batch-processing',
);
// Log only first and last, as the entire batch may be too big.
if ( count( $batch ) > 0 ) {
$error_context = array_merge(
$error_context,
array(
'batch_start' => $batch[0],
'batch_end' => end( $batch ),
)
);
}
/**
* 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.
* @param array $error_context Context to be passed to the logging function.
* @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, $error_context );
$this->logger->error( $error_message, $error_context );
}