Recording rails exceptions

May 7, 2008

Railscast episode 104 shows how to record exceptions on a production site for analysis purposes. It refers to the exception_logger plugin from defunkt.

As Ryan Bates later noted on his blog you probably want to add authentication to the exception_logger controller so not everyone can access it. The README of the plugin shows how to do this.

However, I found the solution provided in the README to be cumbersome, a bit too 'hackish' to my taste, and sadly it didn't work anyways (probably it did work with rails 1.x, but it doesn't with rails 2.x). I also didn't like to copy code that is already present in my ApplicationController and AdminController.

Therefor I forked defunkt's code, refactored it a bit, and now it easily leverages existing (authentication) code in your controllers.

To see it in action:

git submodule add git://github.com/lawrencepit/exception_logger \
vendor/plugins/exception_logger

and then create this controller for example:

class LoggedExceptionsController < AdminController
  include ExceptionLoggableControllerMixin
  self.application_name = "My Application Name"
end

So basically all you have to do is include the module ExceptionLoggableControllerMixin in your own controller.

The source of my fork can be found at http://github.com/lawrencepit/exception_logger


Comments

No comments yet.

Leave a comment