I mean when i can use var_dump() and mage::log().

I have some idea about log. if we enable log settings and for example if we use mage::log($obj).it will print $obj information in system.log file.

where as var_dump() print direclty in browser.

Please comment if i'm anything wrong.

  • 1
    No one mentioned this,but I don't feel it deserves its own answer...var_dump() can cause "Headers already sent" exceptions in some cases, so be careful with using that. Jun 6, 2014 at 16:48

6 Answers 6


var_dump() shows the information in your browser. Mage::log() echos information to your system.log file (var/log/system.log).

To use Mage::log(), you need to enable logging in the backend: System > Configuration > Developer -> Log Settings -> Enabled > Set to "Yes".

Furthermore you can force logging using the forth parameter of Mage::log() set to true: Mage::log($foo,null,'system.log',true);

According to the function in Mage.php: public static function log($message, $level = null, $file = '', $forceLog = false)

Mage::log() will be especially useful if you do not see the output in your browser (debugging SOAP API requests, AJAX requests,...).


You are right.

var_dump() will print in your browser, so it can only be used when you debug locally.

In contrast, Mage::log() prints to a log file. So you can use Mage::log() even on production systems, since you can view the output "hidden" from the user.


output buffering:

ob_start(); var_dump($object_var_array); $dump= ob_get_clean(); Mage::log( "**dumping: {$dump}", null, 'mydumped.log' );

I use this when I need to find something on a live site and do not want to be printing a bunch of garbage to the screen. I would not leave it on for all time, just for testing..


I'm finding another advantage of mage::log() over var_dump().

for example saveBillingAction() method in onepagecontroller.php

      $data = $this->getRequest()->getPost('billing', array());
            Mage::log($data);//it's  working perfectly
var_dump($data);//its not working.(i don't know exact reason.i think ajax calls)

If you want to log variable information, you can use Mage::log(print_r($var, true)) as well.

Also, you can specify your own log files in Mage::log. Generally when I'm debugging I output to a log file specific to the module. Mage::log('Something', null, 'mylog.log')


var_dump / print_r can only provide reasonably meaningful/trackable information when you work on templates. It'll royally screw up forwarding however and Magento uses that extensively.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.