Custom Magento Module Log

PHP errors and messages from other modules can clutter up your tail -f when debugging, and sometimes it’s just nice to have separate logs to the main system.

Set up your own log adapter with:

$my_log = Mage::getModel('core/log_adapter', 'my_module.log');

and log away!

$my_log->log($message);

Extra points for wrapping it up in a class:

class Nick_Module_Model_Log {
  protected $_adapter;
 
  public __construct() {
    $this->_adapter = Mage::getModel('core/log_adapter', 'my_module.log');
  }
 
  // It's public incase we want to use ->debug(), ->info(), and friends
  public function getAdapter() {
    return $this->_adapter;
  }
 
  public function log($message) {
    $this->getAdapter()->log($message);
  }
}
 
$my_log = Mage::getSingleton('nick/log');
$my_log->log("Logging away!");

Posted by Nick.

About Nick: Refuses to wear shoes in the office but does not resent having an incredibly common name. Technical Director at Meanbee.

View the original version of this post.

Leave a Reply

  • You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Tweets from @meanbee

Contact Meanbee

Send us your message