Magento comes with a built-in logging facility which can be enabled and configured in the back-end under System > Configuration > Developer. Alternatively you can enable the Developer Mode for the site to enable the log (on how to do this have a look at the index.php file). The exception log is always on.
Mage::log('My log entry');
Mage::log('My log message: '.$myVariable);
Mage::log($myArray);
Mage::log($myObject);
Mage::logException($e);
By default all log entries are appended to the var/log/system.log file and the exceptions are logged to var/log/exception.log. Objects and Arrays are automatically written via a print_r() directive. Watch out when using objects since these can get substantial in size. If you are in Developer Mode you can try if the object supports debug output via $object->debug().
Tip:
When using
Mage::log($myVariable);
If $myVariable is empty you won’t get an entry in the log. Add a comment before and at least you will know that the variable at that stage is empty:
Mage::log('My variable: '.$myVariable);
If you are distributing your own extensions it helps a lot if you don’t have to sift through heaps of unrelated log entries to identify an issue. The solution is to log to your own files.
Looking at the method definition in app/code/Mage.php you will find
public static function log($message, $level = null, $file = '') {}
so logging to your own file becomes as easy as
Mage::log('My log entry', null, 'mylogfile.log');
and et voilá all our log entries are in their own file at var/log/mylogfile.log. Exceptions can only be logged to one file
Originally published on magebase.com. Copyright © 2010 Magebase - All Rights Reserved.




Proud members of the 









Great article very useful!!!
Thanks a lot for your tips
I use Mage::log to dump object, but nothing saved. what’s wrong?
Did you enable logging in: System > Configuration > Developer?
If so, where are you looking? The log is in: [magento-root]/var/log/
Also, how are you dumping the object?
I seem to have a similar problem as “Magento”. Logging is enabled. And I use a static
Mage::log("Hello world.");But nothing happens. Am I doing something wrong?
Are you sure your statement is executed? Where are you putting it? Does your web server process have write rights to var/log?
Hi!
I was having the same problem and I thought something was wrong. Just to be clear:
1. Enable developer mode in the .htaccess file by adding:
SetEnv MAGE_IS_DEVELOPER_MODE=true
2. Enable log settings going to:
System » Configuration » Developer, Log settings tab » Enabled » Yes.
Then… it worked!
Thanks Robert for this post. I’m just starting with Magento and it’s kind of weird for me not be able to use «echo» whereever I wont to find issues or to know where I am. I hope this log helps me!
[...] Log files Share → (function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk')); (function() { var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true; po.src = 'https://apis.google.com/js/plusone.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s); })(); Tweet !function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs"); /* [...]