codegooglecom / rend

Automatically exported from code.google.com/p/rend
Other
0 stars 0 forks source link

Need Log Action Helper #23

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
<?php
/**
 *
 */

/** Rend_Controller_Action_Helper_Abstract */
require_once 'Zend/Controller/Action/Helper/Abstract.php';

/**
 *
 */
class Rend_Controller_Action_Helper_Log extends
Zend_Controller_Action_Helper_Abstract
{

    /**
     * Log object
     * @var     Zend_Log
     */
    private $_log;

    /**
     * Get the log object
     *
     * @return  Zend_Log
     */
    public function direct()
    {
        return $this->getLog();
    }

    /**
     * Get the log object
     *
     * @return  Zend_Log
     */
    public function getLog()
    {
        if (!$this->_log) {
            try{
                $this->_log =
$this->getActionController()->getInvokeArg('rendFactoryLoader')->log();
            }catch(Rend_FactoryLoader_Exception $e){
                // log not setup
                $this->_log = new Zend_Log();
                $this->_log->addWriter(new Zend_Log_Writer_Null());
            }
        }
        return $this->_log;
    }

}

Original issue reported on code.google.com by konrn...@gmail.com on 1 Dec 2008 at 10:22

GoogleCodeExporter commented 9 years ago
Thanks for the submission. I'll probably take a slightly different approach that
requires a log object to be assigned via a setter before use.

Original comment by justin.h...@gmail.com on 1 Dec 2008 at 10:34

GoogleCodeExporter commented 9 years ago
Okay. Either way, getLog() will need to return an instance of Zend_Log, so anull
writer will need to be added, right?

Original comment by konrn...@gmail.com on 3 Dec 2008 at 5:17

GoogleCodeExporter commented 9 years ago
Technically speaking, I'm decoupling the creation of the log object from the 
helper,
making it something the user has to do, which would include creating a log with 
a
null writer.

To bridge the gap, the default behavior of the log factory could be changed to
include a null writer to prevent errors "out-of-the-box". Currently the log 
factory
loads /application/config/log.php, which is empty, to setup the log object.

Original comment by justin.h...@gmail.com on 3 Dec 2008 at 4:55