Trap and error log, warnings, notifications in the Zend Framework

I am currently using a basic error controller that 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 does not register any warnings, notifications, and fatal errors.

I would also like to register them. Is there a recommended way to do this in ErrorController? Or should it be done outside the ErrorController in index.php (since the Zend Framework ErrorHandler will only handle the route, missing exceptions for the application / action and exceptions in the action controllers)?

+3
source share
1 answer

Source: https://habr.com/ru/post/1757967/


All Articles