Adding Debug Messages to a Magento Module

Jun 4, 2011

How to: MagentoWhen you start building your own Magento modules/plugins, or even just resort to looking at the code to try to work out how to things need to be in your templates it is often useful to output debugging information. Magento helpfully provides such a facility but it is a bit tricky to find.

Buried away in the depths of the System->Configuration menu under Advanced – Develop and then Log Settings you can turn on logging. Once you have done this you can use the following code snippet from inside a module (and perhaps even a template) to write to a log file.

Mage::log("Some useful debugging information");
Mage::log("That will help you develop your Magento shop");

The log file will be created in your stores var/log folder in the system.log file. The exception.log file is also pretty useful since Magento normally hides error messages from the front-end of the site.

Good luck with your Magento plugins – I do, of course, expect a credit :-)