Magento Development Environment

本文提供了Magento开发的实用建议,包括如何启用日志记录以便快速定位问题,以及如何开启开发者模式以获得更详细的错误报告。

Magento Development Environment

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$variableto 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 withsystem.logandexception.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 usingMage::Logwill 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 loveCommerce 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 copyand start workingwithMagento instead of against it.

Read more about Magento
Originally published July 2, 2009
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值