John Watson

Hello! My name is Watson and I’m a freelance web developer. I create web sites using the latest tech for clients both huge and small. Contact me and I’ll help you build your dream project.

Magento debugging tips

This helped debug some problems I was having with observers not doing what I was expecting.

  1. Login to your Magento admin and enable logging: Configuration | Developer | Log Settings | Enabled = Yes
  2. Add Mage::log() statements to your code. For example, in your observer callback: Mage::log(“My special observer called”)
  3. Watch the log files. In Linux, the tail command is very helpful for this. From the /var/log folder: tail -f system.log exception.log
Some more tips:
  • Include print_r() output in the log like this: Mage::log(“myvar = ” . print_r($myvar, true))
  • Add to the exception.log using Mage::logException()
  • The Mage class has some useful helper functions (/app/Mage.php)
  • Get the actual class name of any object: $name = get_class($object)
  • If you copy and paste this code, you’ll probably need to fix the fancy quotation marks.