Do you want to be notified when an exception is raised in your code? This code is for you. I wrote an application resource that will send you a nicely formatted email with all the data about the exception. In order to use it you have to install my library and insert the following lines into your application.ini file
autoloadernamespaces[] = "Zle_" pluginPaths.Zle_Application_Resource = "Zle/Application/Resource"
Then you’ll have to setup the application resource using the following directives
; notifier settings resources.notifier.project = Project Name resources.notifier.addresses[] = foo@example.com resources.notifier.addresses[] = bar@example.com
This snippet of code attachs an email log writer to the log resource, so don’t forget to configure the log resource in application.ini file. The generated email will be sent using the default transport, so you’ll have to configure it otherwise the default transport (sendmail) would be used.
The default error controller will log any error with the CRIT priority, this will trigger the writer and send a message like this one to the given recipients:
You would like to avoid to receive notifications for a page not found (otherwise all the request generated by script kiddies would flood your inbox), in order to do this you can edit the default error controller to keep track of that in this way:
public function errorAction()
{
$errors = $this->_getParam('error_handler');
$logError = true;
// skipped code
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:
$logError = false;
// other case for the switch
// Log exception, if logger available
if ($logError && $log = $this->getLog()) {
$log->crit($this->view->message, $errors->exception);
}
Last but not least, when you are in development or in testing mode you can avoid notifications by using this line in the right section of your application.ini
; disable notifier for development resources.notifier.disabled = true




















