有没有更好的方法来获得全局可访问的 Zend_Log 对象?
在 Bootstrap.php 中我正在做:
protected function _initLogging()
{
$logger = new Zend_Log();
$writer = new Zend_Log_Writer_Stream(APPLICATION_PATH . '/../app.log');
$logger->addWriter($writer);
Zend_Registry::set('log', $logger);
}
然后在整个应用程序中我将使用:
Zend_Registry::get('log')->debug('hello world');
我想这并不可怕。这似乎有点冗长。
最佳答案
引自此newsgroup entry :
class My_Helper_Logger extends Zend_Controller_Action_Helper_Abstract
{
function init()
{
$this->getActionController()->logger = $this->getActionController()
->getInvokeArg('bootstrap')
->getResource('logger');
}
}
to apply the helper all you have to do is to put in the init() function of Michael's example this line:
Zend_Controller_Action_HelperBroker::addHelper(new My_Helper_Logger());
and in every action of your controllers now you can access the logger as $this->logger
还有许多其他建议,请查看链接。
关于php - 更好地实现全局 Zend Log 实例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2059557/