Question

I want to use Zend Framwork's Log mechanism as a separated component,that means all I want from ZF is just the Log, How can I do this?

Was it helpful?

Solution

According to these two pages

Zend_Log requires Zend_Exception and the following

  • DOM
  • libxml
  • Reflection

What this means is that you really only need the following from the framework itself

library/Zend/Exception.php
library/Zend/Log.php
library/Zend/Log <- the directory

You should then be able to use the logger as a stand-alone component. Just add the library folder in the list above to your include path (Zend Framework components rely on this)

set_include_path(implode(PATH_SEPARATOR, array(
    '/path/to/library',
    get_include_path()
)));

require_once 'Zend/Log/Writer/Stream.php';
require_once 'Zend/Log.php';

$writer = new Zend_Log_Writer_Stream('/path/to/logfile');
$log = new Zend_Log($writer);
$log->log('Some message', 1);

OTHER TIPS

Whenever I want to use individual components from Zend Framework I simply include a small file called zend_setup.php that contains the following three lines of code:

set_include_path( '/Users/me/workspace/proj_name/library' . PATH_SEPARATOR . get_include_path());
require_once( '/Users/me/workspace/proj_name/library/Zend/Loader/Autoloader.php' );
Zend_Loader_Autoloader::getInstance();

This is probably not as efficient as issuing explicit require_once() statements, but I like the convenience it offers. For example, you may very quickly decide you also want to utilize Zend_Log_Writer_Firebug() and Zend_Log_Writer_Mail(). Using the autoloader avoids having to write all those additional require_once() statements.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top