Sugitime
Sugitime

Reputation: 1888

ZendFramework Log Errors

I'm trying to log all application errors easily. Does ZendFramework have a plugin that can do this, or can it do this natively?

Upvotes: 2

Views: 5240

Answers (4)

es cologne
es cologne

Reputation: 3614

To log all Error types (also PHP Fatal Error):

    register_shutdown_function( 'myErrorHandler' );
    function myErrorHandler() {
      $error = error_get_last();
      if( $error !== NULL) {
        getMyZendLogger->log("got error: ".$error["message"], Zend_Log::ERR);
      }
    }

See How do I catch a PHP Fatal Error

Zend_Log::registerErrorHandler() (Zend-FW 1.12) catch not all errors

Upvotes: 0

RDK
RDK

Reputation: 4560

also you can use in your Controller

try{
} catch(Zend_Exception $e){
    echo $e->getMessage
    (or log errors in log file using Zend_Log) 
}

Zend_Log

Zend_Exception

Upvotes: 1

Artur Michalak
Artur Michalak

Reputation: 459

Type in your configuration:

phpSettings.log_errors = 1
phpSettings.error_log = "/path_to_yours_application_logs/php.log"

This puts all error logs to php.log file. It's common approach in production environment.

Upvotes: 6

Alex
Alex

Reputation: 6470

Zend includes standard error handling plugin that redirects to ErrorController. Here are 2 solutions:

  1. Create Zend_Controller_Plugin_ErrorHandler and register in bootstrap/controller
  2. Create custom PHP error handler

Upvotes: 2

Related Questions