Debug – Difference Between var_dump() and Mage::log()

debuglog

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.

Best Answer

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,...).

Related Topic