I'm developing a module on a vanilla install of CE I'm trying to write to a custom log file inside the module's observer. The log file is created but remains empty no matter what. Here's my code:



And the Observer:


class My_Module_Model_Observer
    public function observeSummin( $observer ) {
        if ( !$this->_isEnabled ) {
            Mage::log( 'is-enabled, 1: ', 'no', 'my_module.log', true );

        Mage::log( 'is-enabled, 1: ', 'yes', 'my_module.log', true );

        $quoteItem = $observer->getEvent()->getQuoteItem();

        if ( $this->cartQualifies() ) {
            if ( $quoteItem ) {
                Mage::log( 'cart-qualifies, 1: ', 'yes', 'my_module.log', true );
        } else {
            Mage::log( 'cart-qualifies, 1: ', 'no', 'my_module.log', true );


As you can see, I've just dumped loads of log instances to catch any conditions. Apart from the checkout_cart_product_add_after event, I've also tried hooking into the sales_quote_add_item and checkout_cart_save_after events, with the same results.

If I introduce an intentional code error in the observer, the error log catches it, otherwise, there are none. I've also tried to use Mage::log without the file parameter, but nothing is written to system.log.

The entire var/ folder is chmod 777 and logging is enabled in system config.

I'm lost as to why it's not logging - other Magento events are being logged in system and exception. Any suggestions would be appreciated, thanks!

  • have you enable from backend ?
    – Keyul Shah
    Commented May 1, 2014 at 16:07
  • 2
    @KeyulShah The boolean true as the fourth param overrides configuration setting.
    – benmarks
    Commented May 1, 2014 at 16:09

1 Answer 1


Perhaps you mean to concatenate the first two arguments (. instead of ,)? In any event, your second argument is being filtered out by the Zend_Log component.

Look at the Mage::log() definition:

public static function log($message, $level = null, $file = '', $forceLog = false)
    $level  = is_null($level) ? Zend_Log::DEBUG : $level;

According to this use of Zend_Log, your second argument need to be an integer between 0 and 7; best to use the constants though:

class Zend_Log
    const EMERG   = 0;  // Emergency: system is unusable
    const ALERT   = 1;  // Alert: action must be taken immediately
    const CRIT    = 2;  // Critical: critical conditions
    const ERR     = 3;  // Error: error conditions
    const WARN    = 4;  // Warning: warning conditions
    const NOTICE  = 5;  // Notice: normal but significant condition
    const INFO    = 6;  // Informational: informational messages
    const DEBUG   = 7;  // Debug: debug messages
  • (slaps forehead) Thx Ben, this is working: Mage::log( 'cart-qualifies: ', null, 'my_module.log', true );
    – Jongosi
    Commented May 1, 2014 at 19:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.