How to print array contents in log file?
Mage::log(print_r($arr, 1), null, 'logfile.log');
Adding a second parameter to print_r will return a string with printed variable.
based on the comments below I feel obligated to offer other options for logging an array.
Mage::log($arr, null, 'logfile.log');
or if you need a string prefix to the array
Mage::log('prefix'.Zend_Debug::dump($arr, null, false), null, 'logfile.log');
The second parameter of
Zend_Debug::dump()is a label. If this is not
nullit will be added to before the array dump.
The third parameter of
echo. If it's
truethen the dump result will be echoed, if it's
falseit will be returned as a string. In your case you need it to be
Thanks. It worked perfectly. I think you have missed the comma between the parameters of print_r function. Instead there was a full-stop.
You shouldn't need the `print_r` here, Magento's logger will autoexpand arrays and objects
If you insist on using `print_r`, a better choice might be to use `Zend_Debug::dump($var)`.