Categories


Archives


Recent Posts


Categories


Magento Development Environment

astorm

Frustrated by Magento? 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.

No Frills Magento Layout is the only Magento front end book you'll ever need. Get your copy today!

This entry is part 5 of 43 in the series Miscellaneous Magento Articles. Earlier posts include Magento Front Controller, Reinstalling Magento Modules, Clearing the Magento Cache, and Magento's Class Instantiation Abstraction and Autoload. Later posts include Logging Magento's Controller Dispatch, Magento Configuration Lint, Slides from Magento Developer's Paradise, Generated Magento Model Code, Magento Knowledge Base, Magento Connect Role Directories, Magento Base Directories, PHP Error Handling and Magento Developer Mode, Magento Compiler Mode, Magento: Standard OOP Still Applies, Magento: Debugging with Varien Object, Generating Google Sitemaps in Magento, IE9 fix for Magento, Magento's Many 404 Pages, Magento Quickies, Commerce Bug in Magento CE 1.6, Welcome to Magento: Pre-Innovate, Magento's Global Variable Design Patterns, Magento 2: Factory Pattern and Class Rewrites, Magento Block Lifecycle Methods, Goodnight and Goodluck, Magento Attribute Migration Generator, Fixing Magento Flat Collections with Chaos, Pulse Storm Launcher in Magento Connect, StackExchange and the Year of the Site Builder, Scaling Magento at Copious, Incremental Migration Scripts in Magento, A Better Magento 404 Page, Anatomy of the Magento PHP 5.4 Patch, Validating a Magento Connect Extension, Magento Cross Area Sessions, Review of Grokking Magento, Imagine 2014: Magento 1.9 Infinite Theme Fallback, Magento Ultimate Module Creator Review, Magento Imagine 2014: Parent/Child Themes, Early Magento Session Instantiation is Harmful, Using Squid for Local Hostnames on iPads, and Magento, Varnish, and Turpentine.

Learning Magento can range from frustrating to infuriating for the first time user. Here’s a few tips to ease the burden of assimilating an entirely new system.

Turn on Logging

While the Magento Community Edition doesn’t have much default logging, it does have a solid logging system in place. Anywhere you can execute PHP in Magento you can do something like

Mage::Log($variable);

Magento will output the contents $variable to a log. Arrays and Objects are auto-expanded and pretty printed, allowing you quickly zoom in on the portion of the data structure you’re interested in. I’ve found using this in combination with Mac OS X’s Console.app to be a much smoother experience than dumping objects to the browser, particularly given how often Magento objects store references to a good portion of the system (resulting is large object data dumps).

Logging is turned off by default, to change that

  1. In the Magento Admin, go to System->Configuration
  2. In the left column, click on Developer (under Advanced)
  3. If it’s not expanded, Click on Log Settings
  4. Select Yes from the “Enabled” drop down
  5. Click on Save Config

Unfortunately, Magento won’t create your log files for you. If they don’t exist you’ll need to create them yourself. By default, log files are stored at

var/log/system.log
var/log/exception.log

If the log folder doesn’t exist, create it along with system.log and exception.log. Make sure Apache has write access to both the directory and the files. Check with your system administrator on the best way to do this.

Calls made using Mage::Log will be dropped in system.log. Exceptions will be logged to exception.log

Turn on Developer Mode

If you look in the Magento bootstrap file (index.php) you’ll see lines similar to the following

#Mage::setIsDeveloperMode(true);
 #ini_set('display_errors', 1);

Uncomment these. In a production system, you’d never want to have your errors display to the browser, but while developing having an errors and warnings thrown immediately in your face is invaluable.

Setting the IsDeveloperMode flag is a big time saver. By default, when Magento discovers an exception, it will log the exception to a report and then forward the user to a page that will display that report. This can be infuriating when you’re developing, particularly because Magento redirects in such a way that you can’t backup to the page you were just on. Setting the developer mode flag results in the Exception output being sent directly to the browser with <pre> formatting.

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.

Read more about Magento
Originally published July 2, 2009
Series Navigation<< Magento’s Class Instantiation Abstraction and AutoloadLogging Magento’s Controller Dispatch >>