Zend_Log in application.ini

是否有任何示例如何从 application.ini 设置 Zend 日志的实例?我只找到了一个记录到文件的示例,但我想登录到 SQLITE 数据库表?

is there any example how to setup an instance of zend log from application.ini? I have only found an example for logging to an file, but i want to log into an SQLITE database table?

Zend 日志资源

推荐答案

好问题.我找不到从引导程序配置实例化 Zend_Log_Writer_Db 的方法.writer 类需要一个 Zend_Db_Adapter 对象.它不接受字符串.

Good question. I can't find a way to instantiate the Zend_Log_Writer_Db from a bootstrap config. The writer class requires a Zend_Db_Adapter object. It doesn't accept a string.

采埃孚项目需要进一步开发这个用例.他们甚至没有任何包含数据库编写器的 Zend_Application_Resource_Log 单元测试.

The ZF project needs to develop this use case further. They don't even have any unit tests for Zend_Application_Resource_Log that include a Db writer.

在那之前我最好的建议是,您的 Bootstrap 类需要在 _initLog() 方法中自定义 Log 资源.

The best I can suggest until then is that you Bootstrap class needs to customize the Log resource in an _initLog() method.

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{

  protected function _initDb()
  {
    if ($this->hasPluginResource("db")) {
      $r = $this->getPluginResource("db");
      $db = $r->getDbAdapter();
      Zend_Registry::set("db", $db);
    }
  }

  protected function _initLog()
  {
    if ($this->hasPluginResource("log")) {
      $r = $this->getPluginResource("log");
      $log = $r->getLog();

      $db = Zend_Registry::get("db");
      $writer = new Zend_Log_Writer($db, "log", ...columnMap...);
      $log->addWriter($writer);

      Zend_Registry::set("log", $log);
    }
  }

}

相关文章