Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend_Log in application.ini

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

like image 770
opHASnoNAME Avatar asked Dec 28 '09 06:12

opHASnoNAME


3 Answers

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

}
like image 67
Bill Karwin Avatar answered Nov 09 '22 11:11

Bill Karwin


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

like image 44
sanders Avatar answered Nov 09 '22 11:11

sanders


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"  
like image 1
Shane O'Grady Avatar answered Nov 09 '22 12:11

Shane O'Grady