Search code examples
zend-frameworkzend-log

How to use Zend Log as a separated component?


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?


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