Skip to content

Instantly share code, notes, and snippets.

@stevelounsbury
Created May 19, 2010 17:12
Show Gist options
  • Select an option

  • Save stevelounsbury/406559 to your computer and use it in GitHub Desktop.

Select an option

Save stevelounsbury/406559 to your computer and use it in GitHub Desktop.
/**
* ZF Controller Action helper for logging. Assumes you have the log resource
* setup in your bootstrap, but silently fails if it is not found.
*/
class My_Action_Helper_Log extends Zend_Controller_Action_Helper_Abstract
{
/**
* @var Zend_Log
*/
protected $_log = null;
public function init()
{
$this->_log = $this->getActionController()
->getInvokeArg('bootstrap')
->getResource('log');
}
public function log($message, $level = Zend_Log::DEBUG)
{
if ($this->_log == null) {
return;
}
return $this->_log->log($message, $level);
}
public function __call($name, $arguments)
{
if ($this->_log == null) {
return;
}
return $this->_log->__call($name, $arguments);
}
}
@stevelounsbury
Copy link
Copy Markdown
Author

Hmm, is calling __call directly on $this->_log evil?

@jboesch
Copy link
Copy Markdown

jboesch commented May 19, 2010

Good god that's some hot zend action right there.

@elazar
Copy link
Copy Markdown

elazar commented May 19, 2010

I honestly tend to prefer putting logging in a fat model layer and keeping my controllers thin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment