Logging Magento’s Controller Dispatch

I’m taking a quick break from the Magento series as I plumb the depth of EAV and get through a crunch phase at The Day Job™. In the selfless interest of helping out the internet and the selfish interest of keeping my front page free of moldy content, I thought I’d pass on a simple Controller dispatch logging patch for Magento. This is mainly useful when you’re setting up a new Module and can’t figure out why Magento won’t see it, or if Magento keeps throwing the CMS 404 page in your face

A Few Caveats

  1. These files are not a true Magento Module. While powerful, creating something like this with Magento’s override system would be an order of magnitude harder

  2. Because of the above, I can’t make any promises about using this with a anything but Magento version 1.3.2.3

  3. Standard caveats about production servers apply. Use at your own risk, no warranties, etc.

Installing

Take the “Mage” folder (1.3.2.3/Mage) and place it in

app/code/local

so that your directory tree looks like

local/Mage/Core/Controller/Varien/Action.php
local/Mage/Core/Controller/Varien/Front.php
local/Mage/Core/Controller/Varien/Router/Standard.php
local/Mage/Core/Model/App.php

Then, enable logging and you should start seeing messages in your system.log that look something like

2009-09-20T16:55:48+00:00 DEBUG (7): Matching router [standard] = Mage_Core_Controller_Varien_Router_Standard  vs. request
2009-09-20T16:55:48+00:00 DEBUG (7): Module: helloworld
2009-09-20T16:55:48+00:00 DEBUG (7): Found Modules: Array
(
    [0] => Alanstormdotcom_Helloworld
)

2009-09-20T16:55:48+00:00 DEBUG (7): Setting Route Name [helloworld] on request
2009-09-20T16:55:48+00:00 DEBUG (7): Passing request into controller Alanstormdotcom_Helloworld_IndexController
2009-09-20T16:55:48+00:00 DEBUG (7): Setting Module Name to: helloworld at Mage_Core_Controller_Varien_Router_Standard::match(248)
2009-09-20T16:55:48+00:00 DEBUG (7): Setting Controller Name to: index at Mage_Core_Controller_Varien_Router_Standard::match(250)
2009-09-20T16:55:48+00:00 DEBUG (7): Setting Action Name to: index at Mage_Core_Controller_Varien_Router_Standard::match(252)
2009-09-20T16:55:48+00:00 DEBUG (7): Calling dispatch method on Alanstormdotcom_Helloworld_IndexController
2009-09-20T16:55:48+00:00 DEBUG (7): Action Controller: Alanstormdotcom_Helloworld_IndexController dispatching with action [index]

You’ll also see a message whenever Magento can’t make a Module, Controller, or Action Method match, which is useful when debugging 404 problems.

Like this article? Then you’ll love Commerce Bug, the must have debugging extension for anyone using Magento. Whether you’re just starting out or you’re a seasoned pro, Commerce Bug will save you and your team hours everyday. Grab a copy and start working with Magento instead of against it.

Originally published September 20, 2009
blog comments powered by Disqus