Showing posts with label debbug. Show all posts
Showing posts with label debbug. Show all posts

Saturday, February 23, 2013

Magento debugging thoughts

Random thoughts on debugging in magento

Logging magento queries

Sometimes you need to take a look at the queries generated by magento while loading different objects or collections. To log queries edit lib/Varien/Db/Adapter/Pdo/Mysql.php and change the following line:
protected $_debug               = false;
to
protected $_debug               = true;
The log file is specified in:
protected $_debugFile           = 'var/debug/pdo_mysql.log';

Logging ALL magento queries

Even with logging enabled not all queries are  logged. To enable logging all queries change:

protected $_logAllQueries       = false;
to
protected $_logAllQueries       = true;

Logging all magento events

To log all the events magento throws edit app/Mage.php and add the following line to the dispatchEvent function:
Mage::log($name, null, 'events.log');

After the change the function should look something like:
public static function dispatchEvent($name, array $data = array())
    {
        Mage::log($name, null, 'events.log');
        Varien_Profiler::start('DISPATCH EVENT:'.$name);
        $result = self::app()->dispatchEvent($name, $data);
        #$result = self::registry('events')->dispatch($name, $data);
        Varien_Profiler::stop('DISPATCH EVENT:'.$name);
        return $result;
    }
Events will be logged to var/log/events.log