Reputation: 1289
I'm trying to log PHP data returning from a call to Paypal to a database using the following code
$db = new Zend\Db\Adapter\Adapter(array(
'driver' => $config->database->adapter,
'database' => $config->database->params->dbname,
'username' => $config->database->params->username,
'password' => $config->database->params->password
));
$paypalLog = array(
'transactionId' => 'transactionId',
'transactionType' => 'transactionType',
'paymentType' => 'paymentType',
'orderTime' => 'orderTime',
'currencyCode' => 'currencyCode',
'feeAmt' => 'feeAmt',
'taxAmt' => 'taxAmt',
'paymentStatus' => 'paymentStatus',
'pendingReason' => 'pendingReason',
'reasonCode' => 'reasonCode'
);
$writer = new Zend\Log\Writer\Db($db, 'paypal', $paypalLog);
$logger = new Zend\Log\Logger();
$logger->addWriter($writer);
$logger->info($transactionId,
$transactionType,
$paymentType,
$orderTime,
$currencyCode,
$feeAmt,
$taxAmt,
$paymentStatus,
$pendingReason,
$reasonCode);
?>
I keep getting the below error
Fatal error: Uncaught exception 'Zend\Log\Exception\InvalidArgumentException' with message '$extra must be an array or implement Traversable' in C:\xampp\htdocs\app\library\Zend\Log\Logger.php:236 Stack trace: #0 C:\xampp\htdocs\app\library\Zend\Log\Logger.php(333): Zend\Log\Logger->log(6, '2SH18664DB63910...', 'expresscheckout') #1 C:\xampp\htdocs\app\public\orderconfirm.php(124): Zend\Log\Logger->info('2SH18664DB63910...', 'expresscheckout', 'instant', '2013-02-06T10:4...', 'AUD', '0.52', '0.00', 'Completed', 'None', 'None') #2 {main} thrown in C:\xampp\htdocs\app\library\Zend\Log\Logger.php on line 236
Any help appreciated.
Upvotes: 1
Views: 1665
Reputation: 1289
I got this working by constructing an array containing the 'extra' information and sending that.
$data = array(
'transactionId' => $transactionId,
'transactionType' => $transactionType,
'paymentType' => $paymentType,
'orderTime' => $orderTime,
'amt' => $amt,
'currencyCode' => $currencyCode,
'feeAmt' => $feeAmt,
'taxAmt' => $taxAmt,
'paymentStatus' => $paymentStatus,
'pendingReason' => $pendingReason,
'reasonCode' => $reasonCode
);
$mapping = array(
'message' => 'message',
'extra' => $data);
$writer = new Zend\Log\Writer\Db($db, 'paypal', $paypalLog);
$logger = new Zend\Log\Logger();
$logger->addWriter($writer);
$logger->info($mapping);
Upvotes: 0
Reputation: 12809
You are using the logger incorrectly.
There's two paramters it accepts:
/**
* @param string $message
* @param array|Traversable $extra
* @return Logger
*/
public function info($message, $extra = array())
{
return $this->log(self::INFO, $message, $extra);
}
You are passing $transactionType as an "extra" field which is probanly not an array or traverable object.
try this, the array should be converted to a string for the log file:
$logger->info(paypalLog);
// or convert it to a string before logging.. it
$logger->info(implode(',', $paypalLog));
Upvotes: 2