Magento Debugging - An Introduction to Magento Exception Logging and Developer Mode

One of the first stumbling blocks newcomers to Magento might find is that when things go wrong, they don’t know how to find out what it is that’s actually going wrong.

This is because Magento does an excellent job of keeping all of the error information away from people browsing the site. This is without a doubt a very good thing. Error messages can often contain information that would help an attacker compromise your system.

What Magento does instead (if you have it enabled) is to log all error information to log files which you can then access via FTP etc to view the error information. This is in much the same way as a well configured web server will not display error information generated by PHP itself but will instead display the “white screen of death” and log the error information to a file.

Magento exceptions can range from minor notices to major issues but not fatal errors. If PHP has a fatal error then this will be handled by PHP itself.

Magento Exception Logging

If you are experiencing errors with Magento, the first thing you need to do is to make sure exception logging is enabled.

In the admin go to:

System->Configuration > Developer > Log Settings > Enabled = Yes

You can also set custom locations for your error log files, though the defaults are normally fine. Make sure the folder is writeable.

Now if you are having errors, you can look in var/log at the exception.log and/or system.log files that have been generated.

Magento Developer Mode

If you are developing locally and you would like to make Magento dump error information to screen instead of logging to a file, this is very easy to do. You simply need to set the site to run in Developer Mode.

The most secure way to do this (in the sense that you won’t accidently set your live store in Developer Mode) is to edit your local apache configuration and add this line:


SetEnv MAGE_IS_DEVELOPER_MODE "true"

You need to set this up in the directory you are running Magento, for example:


<Directory "/opt/lampp/htdocs">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.2/mod/core.html#options
    # for more information.
    #
    #Options Indexes FollowSymLinks
    # XAMPP
    Options Indexes FollowSymLinks ExecCGI Includes
        SetEnv MAGE_IS_DEVELOPER_MODE "true"

Now any Magento site you run from within that folder (or any sub folder) will be running in Developer Mode when you are working locally, but will still be in the much more secure normal mode on the live server, without you having to edit any files within Magento itself.

If you prefer, you can add this line to your .htaccess file, or you can edit the index.php file to force Developer Mode however with either of these approaches there is always the risk you will accidently upload this file and set your live store into Developer Mode.


Tags: magentoexceptionerrordebugginglogdeveloper modeexception log