Don't like ads? PRO users don't see any ads ;-)

#Zend - setup logger

By: yamcsha on Apr 12th, 2012  |  syntax: PHP  |  size: 1.62 KB  |  hits: 33  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
  2. {
  3.     public $frontController;
  4.    
  5.     /**
  6.     * Setup Logging System using Zend_Log and FirePHP
  7.     */
  8.     protected function _initLogging()
  9.     {
  10.         $this->bootstrap('frontController');
  11.  
  12.         // create new Logger
  13.         $logger = new Zend_Log();
  14.        
  15.         // in development Env echo logs in firebug console
  16.         // in production Env write logs to file 'data/logs/app.log'
  17.         $writer = 'production' == $this->getEnvironment()
  18.                     ? new Zend_Log_Writer_Stream(APPLICATION_PATH . '/../data/logs/app.log')
  19.                     : new Zend_Log_Writer_Firebug();
  20.         $logger->addWriter($writer);
  21.        
  22.         // in production Env show logs bellow critical level
  23.         if ('production' == $this->getEnvironment()) {
  24.             $filter = new Zend_Log_Filter_Priority(Zend_Log::CRIT);
  25.             $logger->addFilter($filter);
  26.         }
  27.        
  28.         $this->_logger = $logger;
  29.         Zend_Registry::set('log', $logger);
  30.     }
  31.    
  32.  
  33.     /**
  34.     * setup DB Profiler (only for non production Env)
  35.     */
  36.     protected function _initDbProfiler()
  37.     {
  38.         // example use of logger
  39.         $log = Zend_Registry::get('log');
  40.         $log->info(__METHOD__);
  41.  
  42.         if ('production' != $this->getEnvironment()) {
  43.             $this->bootstrap('db');
  44.             $profiler = new Zend_Db_Profiler_Firebug('All DB Queries');
  45.             $profiler->setEnabled(true);
  46.            
  47.             $this->getPluginResource('db')
  48.                  ->getDbAdapter()
  49.                  ->setProfiler($profiler);
  50.         }
  51.     }
  52.  
  53. }