php - 更好地实现全局 Zend Log 实例?

标签 php zend-framework

有没有更好的方法来获得全局可访问的 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/

相关文章:

php - 如何按类别列出评论? (操作数组)

zend-framework - Zend - 从模块/ Controller / View 逻辑生成语音 URL

php - 如何在 zend db 中使用 union

php - 从句子中删除除选定单词之外的单词

python - 从 PHP shell_exec 执行 Python 脚本以使用 smtp 发送电子邮件失败

zend-framework - Zend move_uploaded_file 失败

zend-framework - Zend Framework 应用程序的日志记录请求

zend-framework - Zend URL 助手和自定义路由?

php - MYSQL 列中有 9,000 个字符串 - 使用哪种数据类型?

javascript - 如何在 php 代码中使用 jQuery 变量?