問題描述
是否有任何示例如何從 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);
}
}
}
這篇關于Zend_Log in application.ini的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!