Zend_Log 在 application.ini 中

发布于 2024-08-16 17:08:39 字数 261 浏览 14 评论 0原文

有没有示例如何从 application.ini 设置 zend log 实例?我只找到了登录到文件的示例,但我想登录到 SQLITE 数据库表?

Zend 日志资源

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 Log resource

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

甜妞爱困 2024-08-23 17:08:39

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

采埃孚项目需要进一步开发这个用例。他们甚至没有任何包含 Db writer 的 Zend_Application_Resource_Log 单元测试。

在此之前我能建议的最好的建议是,Bootstrap 类需要在 _initLog() 方法中自定义日志资源。

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

}

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.

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.

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

}
三生路 2024-08-23 17:08:39

手册中:你可以找到一个如何将日志文件写入数据库的示例。这是你的意思吗?

Here in the manual: you can find an example how to write your log file into the database.Is that what you mean?

穿透光 2024-08-23 17:08:39

这应该可行 - 我稍后将进行全面测试(现在不在我的开发机器上)

Zend_Application_Resource_Log 可以从 application.ini 设置 Zend_Log 的实例

resources.log.writerName = "db"
resources.log.writerParams.db.adapter = "PDO_SQLITE"
resources.log.writerParams.db.dbname = APPLICATION_PATH "/../db/logdb.sqlite"
resources.log.writerParams.db.table = "log"  

This should work - I will test fully later (not at my dev machine now)

Zend_Application_Resource_Log can setup an instance of a Zend_Log from application.ini

resources.log.writerName = "db"
resources.log.writerParams.db.adapter = "PDO_SQLITE"
resources.log.writerParams.db.dbname = APPLICATION_PATH "/../db/logdb.sqlite"
resources.log.writerParams.db.table = "log"  
千鲤 2024-08-23 17:08:39

自 ZF 1.10alpha(至少)以来,以下情况都是正确的。

// e.g. 1 - works
resources.log.firebug.writerName = "Firebug"
// e.g. 2 - fails
resources.log.writerName = "Firebug"

注意:任意数组键“firebug”。当 Zend_Log 工厂搅动资源的日志配置时,示例 1 将作为数组传递给 Zend_Log->addWriter() (触发 _constructWriterFromConfig() 方法),而示例 2 将简单地传递一个字符串(触发异常)。

(我知道这已经很旧了,我正在使用 Firebug 记录器示例,但这同样适用于所有日志编写器)

Since ZF 1.10alpha (at least), the following has been true.

// e.g. 1 - works
resources.log.firebug.writerName = "Firebug"
// e.g. 2 - fails
resources.log.writerName = "Firebug"

NOTE: the arbitrary array key 'firebug'. When the Zend_Log factory churns over the resource's log config, example 1 will be passed as an array to Zend_Log->addWriter() (triggering the _constructWriterFromConfig() method), whilst example 2 will simply pass a string (triggering an exception).

(I know this is old, and I'm using a Firebug logger example, but the same applies to all log writers)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文