
#Zend - setup logger
By:
yamcsha on
Apr 12th, 2012 | syntax:
PHP | size: 1.62 KB | hits: 33 | expires: Never
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
public $frontController;
/**
* Setup Logging System using Zend_Log and FirePHP
*/
protected function _initLogging()
{
$this->bootstrap('frontController');
// create new Logger
$logger = new Zend_Log();
// in development Env echo logs in firebug console
// in production Env write logs to file 'data/logs/app.log'
$writer = 'production' == $this->getEnvironment()
? new Zend_Log_Writer_Stream(APPLICATION_PATH . '/../data/logs/app.log')
: new Zend_Log_Writer_Firebug();
$logger->addWriter($writer);
// in production Env show logs bellow critical level
if ('production' == $this->getEnvironment()) {
$filter = new Zend_Log_Filter_Priority(Zend_Log::CRIT);
$logger->addFilter($filter);
}
$this->_logger = $logger;
Zend_Registry::set('log', $logger);
}
/**
* setup DB Profiler (only for non production Env)
*/
protected function _initDbProfiler()
{
// example use of logger
$log = Zend_Registry::get('log');
$log->info(__METHOD__);
if ('production' != $this->getEnvironment()) {
$this->bootstrap('db');
$profiler = new Zend_Db_Profiler_Firebug('All DB Queries');
$profiler->setEnabled(true);
$this->getPluginResource('db')
->getDbAdapter()
->setProfiler($profiler);
}
}
}