Zend_Log in application.ini
Asked Answered
T

4

5

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

Tegantegmen answered 28/12, 2009 at 6:35 Comment(1)
Iam speaking abount ZF 1.10alpha release..Tegantegmen
O
13

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

}
Optative answered 9/1, 2010 at 20:46 Comment(0)
B
1

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

Blast answered 5/1, 2010 at 13:18 Comment(1)
Hi, no. I want to add the Log Resource to my application.ini. Like DB Adapater and other stuff. In ZF 1.10 is this new resource available.Tegantegmen
P
1

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"  
Princedom answered 8/1, 2010 at 12:47 Comment(1)
Hi, not working (-: "Writer must be an instance of Zend_Log_Writer_Abstract or you should pass a configuration array" $bootstrap = $this->getInvokeArg('bootstrap'); $log = $bootstrap->getResource('log'); $log->info('x');Tegantegmen
D
1

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)

Doncaster answered 3/2, 2012 at 2:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.