問題描述
是否有任何示例如何從 application.ini 設(shè)置 Zend 日志的實(shí)例?我只找到了一個(gè)記錄到文件的示例,但我想登錄到 SQLITE 數(shù)據(jù)庫表?
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 日志資源
推薦答案
好問題.我找不到從引導(dǎo)程序配置實(shí)例化 Zend_Log_Writer_Db
的方法.writer 類需要一個(gè) Zend_Db_Adapter
對(duì)象.它不接受字符串.
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.
采埃孚項(xiàng)目需要進(jìn)一步開發(fā)這個(gè)用例.他們甚至沒有任何包含數(shù)據(jù)庫編寫器的 Zend_Application_Resource_Log
單元測(cè)試.
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);
}
}
}
這篇關(guān)于Zend_Log in application.ini的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!