Git Product home page Git Product logo

exception_notification's Introduction

Exception Notifier Plugin for Rails

The Exception Notifier plugin provides a mailer object and a default set of templates for sending email notifications when errors occur in a Rails application. The plugin is configurable, allowing programmers to specify:

  • the sender address of the email
  • the recipient addresses
  • the text used to prefix the subject line

The email includes information about the current request, session, and environment, and also gives a backtrace of the exception.

Installation

You can use the latest ExceptionNotification gem with Rails 3, by adding the following line in your Gemfile

gem 'exception_notification', :require => 'exception_notifier'

As of Rails 3 ExceptionNotification is used as a rack middleware, so you can configure its options on your config.ru file, or in the environment you want it to run. In most cases you would want ExceptionNotification to run on production. You can make it work by

Whatever::Application.config.middleware.use ExceptionNotifier,
  :email_prefix => "[Whatever] ",
  :sender_address => %{"notifier" <[email protected]>},
  :exception_recipients => %w{[email protected]}

Customization

By default, the notification email includes four parts: request, session, environment, and backtrace (in that order). You can customize how each of those sections are rendered by placing a partial named for that part in your app/views/exception_notifier directory (e.g., _session.rhtml). Each partial has access to the following variables:

@controller     # the controller that caused the error
@request        # the current request object
@exception      # the exception that was raised
@backtrace      # a sanitized version of the exception's backtrace
@data           # a hash of optional data values that were passed to the notifier
@sections       # the array of sections to include in the email

You can reorder the sections, or exclude sections completely, by altering the ExceptionNotifier.sections variable. You can even add new sections that describe application-specific data--just add the section's name to the list (whereever you'd like), and define the corresponding partial. Then, if your new section requires information that isn't available by default, make sure it is made available to the email using the exception_data macro:

class ApplicationController < ActionController::Base
  before_filter :log_additional_data
  ...
  protected
    def log_additional_data
      request.env["exception_notifier.exception_data"] = {
        :document => @document,
        :person => @person
      }
    end
  ...
end

In the above case, @document and @person would be made available to the email renderer, allowing your new section(s) to access and display them. See the existing sections defined by the plugin for examples of how to write your own.

Notification

After an exception notification has been delivered the rack environment variable 'exception_notifier.delivered' will be set to +true+.

Rails 2.3 stable and earlier

If you are running Rails 2.3 then see the branch for that:

http://github.com/smartinez87/exception_notification/tree/2-3-stable

If you are running pre-rack Rails then see this tag:

http://github.com/smartinez87/exception_notification/tree/pre-2-3

Support and tickets

https://github.com/smartinez87/exception_notification/issues

Copyright (c) 2005 Jamis Buck, released under the MIT license

exception_notification's People

Contributors

chuyeow avatar dhh avatar jamis avatar jcxplorer avatar jinzhu avatar josh avatar knzconnor avatar lawrencepit avatar matthewrudy avatar mperham avatar smartinez87 avatar sutto 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.