Check if a module is enabled in Magento 1

Check From Magento Backend

To check if a module is installed, or activated, first take a quick look from your Magento backend.
Go to System > Configuration > Advance (bottom left)
Then check your module name there. If your module’name is here. It is enabled. Even if you see the module output is set to disable.

Check if Magento module is enabled

How to check if a module is enabled programmatically in Magento 1?

Below is the code you can use to check if a module of your Magento is enabled or not.

isModuleEnabled function is implemented in Mage_Core_Helper_Abstract, which is located in app/code/core/Mage/Core/Helper/Abstract.php

Solution for older version of Magento

It might not be implemented in older versions of Magento, e.g. CE.1.4. If it is so, then you can use the following code to check whether a module is enabled.

When and why you need to check if a module is enabled

Checking if module is enabled is needed before you actually start using the module, for example if you want to load the helper of a module on a view, we can the use the code below,

Mage::helper('XXX_XXXX’);

But if you don’t check if the module is enabled or not before, you are likely to get an error when the module is disabled:

Class 'XXX_XXXX_Helper_Data' not found in xxxxxxxxx  on line xxxx

Note: the code above only checks if the module is enabled or installed, if will not check if the module output is enabled or not.

Magento Mage::log Function, Log Level, and Log Location Explained

Magento provides built-in API for logging. When you are developing new modules or debugging an installed module, these APIs could come in handy.

Mage::log Static Function

If you have been touching with Magento backend code, you have probably seen Mage::log() used by developers in their code. See the examples below, you can use this method to log strings, objects, arrays, etc. This static function is defined in Mage.php

Function Arguments

Take a look at the function signature of this function.

It takes 4 arguments:

The log (1) message, you can pass a string, an object, or an array. If it is an object or an array, it will call print_r function to print in a human-readable format.

The log (2) level, which is defined in lib\Zend\log.php. The default value is null,T and the function will automatically use DEBUG when it is null. In addition, you can also set log level as EMER, ALERT, CRIT, ERR, WARN, NOTICE, INFO, DEBUG.  Check out all possible log level below:

(3) File, if you don’t assign a custom log file location,  it will use default location to store log file. Mage::log function will log into /var/log/system.log; Mage::logException() will save exception printing into /var/log/exception.log

Additionally, you can change the default log locations in Magento back-end under

System -> Configuration -> Developer

Magento Enable Log

Note: see the configuration screen above. In order to store your log messages successfully. Remember if your Magento site is NOT in Developer Mode, and you set  ‘Enable’ to NO in the back-end, you will need to set the (4) forceLog to true , which is the forth argument taken by Mage:log function

However, if you are in Developer Mode, your log message should be stored successfully even if you set you set  ‘Enable’ to NO in back-end.

Mage::logException Static Function

logException function is just a wrapper of Mage::log, where level is set to Zend_Log::ERR. And file is set to default exception log location.

Usages

Last, let’s see some common usage of Mage::log function.