views:

81

answers:

1

Currently I am using a basic error controller which looks like this:

class ErrorController extends My_MyController
{

    public function errorAction()
    {
        $errors = $this->_getParam('error_handler');

        switch ($errors->type) {
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
                // 404 error -- controller or action not found
                $this->getResponse()
                     ->setRawHeader('HTTP/1.1 404 Not Found');

                $this->view->headTitle('HTTP/1.1 404 Not Found');
                $this->view->message = 'HTTP/1.1 404 Not Found';

                break;
            default:
                // application error; display error page, but don't change
                // status code

                // Log the exception:
                $exception = $errors->exception;
                $log = new Zend_Log(
                    new Zend_Log_Writer_Stream(
                        BASE_PATH . '/logs/applicationException.log'
                    )
                );
                $log->debug($exception->getMessage() . "\n" .
                            $exception->getTraceAsString());

                $this->view->headTitle('HTTP/1.1 404 Not Found');
                $this->view->message = 'Application error';

                break;
        }

        $this->view->exception = $errors->exception;
    }
}

This, however, only catches and logs application exceptions. It won't log any warnings, notices and fatal errors.

I would like to log those as well. Is there a recommended way to do it in ErrorController? Or should it be done outside of the ErrorController in index.php (since Zend Framework ErrorHandler will only handle no route, missing application/action exceptions and exceptions in action controllers)?

A: 

Notices and warnings aren't (or shouldn't) be application fatal. Fatal errors do what they say on the tin and sometimes can't be caught. But, if you really need to, perhaps look into:

http://php.net/manual/en/function.set-error-handler.php

Ashley