Zend_Log在application.ini中

opH*_*AME 5 php logging zend-framework zend-application

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

Zend Log资源

Bil*_*win 13

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

ZF项目需要进一步开发此用例.他们甚至没有任何单元测试Zend_Application_Resource_Log,包括Db作家.

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

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);
    }
  }

}
Run Code Online (Sandbox Code Playgroud)