Search code examples
zend-frameworkzend-logzend-app-bootstrap

How to make a global Zend_Log with Zend_Application_Bootstrap


I would like to make a global Zend_Log object that I can reach from my Controllers and my Models.

What should I add to my Bootstrap? (My bootstrap extends Zend_Application_Bootstrap)

How then can I reach the logger object from my controller actions and from my model?


Solution

  • As you do with any other class - assign it to the Zend_Registy. I'd suggest setting like this:

    Zend_Registry::set('Zend_Log',$logInstance);
    

    This is a common way, which is used also for translate (set translate instance to 'Zend_Translate' and classes like forms and validators will find it automatically).

    You can use Zend_Registry::get('Zend_Log')->log(...) to log anywhere you want. It's not very good from the point of architecture (you should not use normally), but for log - which can appear practically anywhere in the app from view helpers to controllers and models it's a good thing.