Magento 1.9 – How to Log Messages in Custom Module Install Script

install-scriptlogmagento-1.9module

I would like to know how to log messages in custom module install script.

File path:

app/code/local/Namespace/Modulename/sql/modulename_setup/mysql4-install-0.0.1.php

The script is running fine. I'm able to debug the file and see the SQL error, moreover, core_resource table is updated properly but the message under the catch block is not logged at:

var/log/modulename_setup.log

My script:

<?php

try {
    $installer = $this;
    $installer->startSetup();
    $installer->run("
       CREATE TABL 'dummy_table' (
        'id' int(11) unsigned NOT NULL auto_increment,
         PRIMARY KEY ('id')
       ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    ");
    $installer->endSetup();
} catch(Exception $e) {
    Mage::log('Something went wrong.', null, 'modulename_setup.log');
}

?>

Any suggestions?

Best Answer

Yes I faced the problem before, the only way I managed to get it working was by forcing the log by setting the 4th parameter of Mage::log to true so in your case I suggest you use the following code

Mage::log('Something went wrong.', null, 'modulename_setup.log', true);
Related Topic