2

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?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
castiel
  • 2,675
  • 5
  • 29
  • 38
  • All I mean is how to initialize Zend Log feature – castiel Feb 03 '12 at 02:09
  • The [Zend_Log_Writer manual page](http://framework.zend.com/manual/1.11/en/zend.log.writers.html) seems pretty straightforward. Are you asking for something more than that? – David Weinraub Feb 03 '12 at 04:48

2 Answers2

6

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);
Phil
  • 157,677
  • 23
  • 242
  • 245
1

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.

JamesG
  • 4,288
  • 2
  • 31
  • 36