Magento logs print array contents
Solution 1
You have to return print_r as a string, so print_r($result, true)
should do the trick.
Solution 2
Try it
$array = array('ID' => 1, 'NAME' => 'Amaresh', 'EMAIL' => '[email protected]');
Mage::log($array);
Output
2015-09-18T06:44:24+00:00 DEBUG (7): Array
(
[ID] => 1
[NAME] => Amaresh
[EMAIL] => [email protected]
)
pokero
Updated on June 09, 2022Comments
-
pokero almost 2 years
Mage::log works fine for me, except when it comes to printing array info.
For example, if I have an array $result, and do this:
Mage::log('[CartController: getDeliverLeadTime(country): ' . $result . ')');
In my system.log file I just get: [CartController: getDeliverLeadTime~(country): Array)
*I want it to print the actual structure and contents of the array, as a normal print_r would do.*
If I do a var_dump of the array I get nothing, i.e. [CartController: getDeliverLeadTime~(country): ).
If I do a print_r I get: [CartController: getDeliverLeadTime~(country): 1)
This is a blocker for me as I can't debug what I need to - if anyone could shed any light on how to get Magento to actually print the contents of arrays in the logs, would be much appreciated.
I read on alanstorm.com that its meant to be happen by default, but its not for me.
Thanks Paul
-
pokero almost 12 yearsMax thanks a million for that! Works perfectly, that is a big relief. I can mark the question as answered in 7 minutes, will do so then. Thanks again, Paul.
-
Anton S almost 12 years@pokero don't forget to vote up and accept the answer if it helped you out
-
Fiasco Labs over 11 yearsNice to have print_r log stuff to your custom Magento log file.
-
Bosworth99 over 11 yearshuh. should be straightforward, but this messed me up a lot. easy fix.