An exception_logger mountable engine for Rails 3
Pull request Compare This branch is 1 commit ahead of yuesmart:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Exception Logger Engine for Rails 3

This is a fork of the Rails 3 implementation of exception_logger that implements the functionality as a mountable engine.

If you're looking for the original gem, it is available at


Add the gem to your Gemfile:

gem "exception_logger", :git => "git://"

Then install and run the necessary migrations. Note that if you've already been using the exception_logger gem, there's no need to follow this step.

rake exception_logger:install:migrations
rake db:migrate


Add the following to any controller you want to have logged (or ApplicationController to log all exceptions)

include ExceptionLogger::ExceptionLoggable 
rescue_from Exception, :with => :log_exception_handler

Now, in your routes.rb:

mount ExceptionLogger::Engine => "/exceptions"

Note that “/exceptions” can be anything you like ;)

Recording User Information

If you'd like to record the user that caused the logged exception to be thrown.

in config/application.rb:

config.after_initialize do
  ExceptionLogger::LoggedExceptionsController.class_eval do
    # A string representation of a method or property that contains 
    # a reference to the model instance that should be considered 
    # the Creator of the exception       
    self.creator = "current_user"

    # A method that can be used to return a string value to
    # be used by the views to display the Creator's information
    # Note that the class that :creator belongs to should respond
    # to the method 
    self.creator_name = "full_name"

Exception Notification

by Email

Rails directly provides a plugin called “Exception Notification” ( ).

Just download the plugin and follow the usage instructions from the README file ( ) and add this code to one of your initializer files

# Example: put this to config/initializers/exception_notification.rb
Whatever::Application.config.middleware.use ExceptionNotifier,
  :email_prefix => "[Whatever] ",
  :sender_address => %{"notifier" <>},
  :exception_recipients => %w{}

Restart your server and you are done. (Don't forget to setup your email settings inside your environment files.)


If you want, and believe me you want that, you can add the following lines to your environment to enable Authentication

Example uses the declarative_authorization gem

in config/environment/production.rb:

config.after_initialize do
  ExceptionLogger::LoggedExceptionsController.class_eval do
    # include any custom auth modules you need
    # (declarative authorization gem used)
    # just add any code you want to be included in the controller ;)
    # optional, sets the application name for the rss feeds
    self.application_name = "Your Application Name"

and (if you use declarative_authorization) add this to your authorization_rules.rb file:

role :admin do
  has_permission_on :exception_logger_logged_exceptions, :to => :manage

Testing & Development

Testing should always start before the actual development.

You can test this gem very easily. Just run:

rake test:basic

from the console of the cloned github repository of the exception logger.

This rake task will create a rails app inside the test directory called rails_root and will install the exception logger and migrate the database of that application just in time.

The generator which generates the rails app in your test directory will skip over every existing file, hence if you want to customize a file, then just add/create it.


Copyright © 2010 Roland Guem, 2012 Alex Bevilacqua.

See LICENSE for details.