Giter Site home page Giter Site logo

cakephp_exception_notifier's Introduction

CakePHP Exception Notifier

This is a CakePHP component. When an exception or a error occurs in your CakePHP application, this component sends you an email.
This component is inspired by exception_notification (Ruby on Rails plugin), see http://github.com/rails/exception_notification.

Usage

First, put exception_notifier.php on app/controllers/components in your CakePHP application.
Second, put qdmail.php on app/controllers/components too because excpetion_notifier.php depends on qdmail.php.
Then, add the following code in whichever controller you want to generate error emails (typically AppController). (Change “[email protected]” to the recipient’s mail address)

<?php
class AppController extends Controller
{
    public $components = array('ExceptionNotifier');

    public function beforeFilter()
    {
        $this->ExceptionNotifier->exceptionRecipients = array('[email protected]');
        $this->ExceptionNotifier->observe();
    }
}

And that’s all!

This component is only run when DEBUG configuraton value is 0. If you want to run this component when configuration value is more than 0, pass true to observe method.

$this->ExceptionNotifier->observe(true);

Configuration

Exception error configuration

In default configuration, this component observes exception, notice error, warning error, and fatal error.
If you don’t want to observe notice error and warning error, add the following code.

class AppController extends Controller
{
    public $components = array('ExceptionNotifier');

    public function beforeFilter()
    {
        $this->ExceptionNotifier->exceptionRecipients = array('[email protected]');
        $this->ExceptionNotifier->observeNotice = false;    // don't observe notice error
        $this->ExceptionNotifier->observeWarning = false;   // don't observe warning error
        $this->ExceptionNotifier->observe();
    }
}

If you want to observe strict error, add the following code.

class AppController extends Controller
{
    public $components = array('ExceptionNotifier');

    public function beforeFilter()
    {
        $this->ExceptionNotifier->exceptionRecipients = array('[email protected]');
        $this->ExceptionNotifier->observeStrict = true;    // observe strict error
        $this->ExceptionNotifier->observe();
    }
}

Mail configuration

If you use SMTP protocol when this component send exception mail, add the following code.

class AppController extends Controller
{
    public $components = array('ExceptionNotifier');

    public function beforeFilter()
    {
        $this->ExceptionNotifier->exceptionRecipients = array('[email protected]');
        $this->ExceptionNotifier->useSmtp = true; // use SMTP
        $this->ExceptionNotifier->smtpParams = array(
                                  'host'=>'smtp.example.com',
                                  'port'=>'25',
                                  'from'=>'[email protected]',
                                  'protocol'=>'SMTP',
                               );
        $this->ExceptionNotifier->observe();
    }
}

Copyright

Copyright © 2009-2010 milk1000cc, released under the MIT license.

cakephp_exception_notifier's People

Contributors

k1low avatar milk1000cc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.