#104
May 05

Exception Notifications

If you're running a production site, it's a good idea to record all exceptions which occur. See how to set up a notification system which does that in this episode.
Download (18.6 MB, 8:58)
alternative download for iPod & Apple TV (12.2 MB, 8:58)
Links

Note: I forgot to mention, the exception_logger plugin requires will_paginate, so make sure you have that installed either through a plugin or gem.

Also I should have mentioned the importance of adding authorization to the controller so not everyone can access it. The README shows you how to do this.

gem install will_paginate
git clone git://github.com/ryanb/exception_logger.git vendor/plugins/exception_logger
script/generate exception_migration
rake db:migrate
# config/environments/development.rb
config.action_controller.consider_all_requests_local = false

# in controllers/application.rb
include ExceptionLoggable

private

def local_request?
  false
end

# routes.rb
map.connect "logged_exceptions/:action/:id", :controller => "logged_exceptions"

17 comments:

Olli May 05, 2008 at 03:03

Maybe its a cool idea to use jabber (aka xmpp) for exeption notification to the admin.


Collin VanDyck May 05, 2008 at 05:39

I always look forward to seeing a new episode in my Railscasts feed. It's very helpful to know how to simulate the production error environment, and the reporting plugin looks really nice. Keep up the good work!


Falk May 05, 2008 at 08:21

Like always, thanks a lot for your effort!


Russ Jones May 05, 2008 at 09:05

Doesn't appear to work with Fast Sessions. http://code.google.com/p/rails-fast-sessions/ No matter what I do I get an error complaining ... "No :secret given to the #protect_from_forgery call" on line #53 of logged_exceptions/index.rhtml ... even though I do have one specified. The errors are logged, but the logged_exception views wont show.


Russ Jones May 05, 2008 at 09:54

Not to sound ungrateful! Love your stuff of course! I'm on the edge of my seat with each episode. You're one of the reasons I love R(uby|ails)!


Jeremy May 05, 2008 at 12:22

Hi

all the same as Russ Jones : the problem with the :secret and the love of your work !

I don't use Rails Fast Sessions, but I disabled session store in cookies. Maybe it's something like that.


Ryan Bates May 05, 2008 at 12:46

@Russ & Jeremy, oh interesting, I hadn't tried this without using cookie session store. It may have something to do with the fact that LoggedExceptionsController doesn't inherit from ApplicationController. You may need to add some specific session info to the controller, check out the readme for an example. I'll do some testing and post what I find.

In many ways I wish this plugin was just a generator which created the controller instead of keeping it buried in a place where it's difficult to change. This would solve these kinds of problems.


kino May 05, 2008 at 13:03

maybe will_paginate portage to git?


Clemens Kofler May 05, 2008 at 13:09

Nice episode!

If - for whichever reason - you don't want to use one of the plugins, there's another possibility that I'm currently using in one of my projects: I symlinked the production.log in the public directory (of course it's password protected) so I can check the log at any time and don't have to log in at the server.


Leland May 05, 2008 at 14:10

Rocking the cas bah. Thanks.


QuBiT May 06, 2008 at 06:02

Nice one, really helpful!

Got it running ^^, just quick and dirty.

for those who had problems with the "secret"

just use:
protect_from_forgery :secret => 'mytinylittleveryultramegalongsecret'

with your secret in the logged_exceptions_controller.rb

and for me i had to use:
helper_method :filtered? and copy that method from the helper file (logged_exceptions_helper) to the controller file in the plugin/lib, because it looks like that the helper is not loading correct.

would be nice, if the logging process itself would be written to the log file ("INSERT INTO ...") for better documentation ... etc etc


Heiko May 06, 2008 at 07:08

What I do for security reasons is putting any admin or reporting pages into a separate application, as described here:

http://www.rorsecurity.info/2008/03/03/intranet-and-admin-security/

This is deescalation, a stolen cookie/session/account means less harm.


Mike Boone May 06, 2008 at 14:31

Does anyone know what's to become of the code on dev.rubyonrails.org that didn't get migrated to GitHub? Stuff like plugins/exception_notification and adapters/oracle.

Thanks for the Railscasts!


Antonio Reina May 07, 2008 at 11:55

Hi

I think that in #config/environments/production.rb code to require authentication, you need add after: accepts.html { login_required_without_basic }
other line for rjs format:
accepts.js { login_required_without_basic }

Moreover, the plugin requires RedCloth gem for exceptions details.


Andreas Neuhaus May 07, 2008 at 13:05

I didn't try exception_logger yet, but it looks promising. I had a quick look to the source and saw, that it provides an RSS feed of logged exceptions - so you can use a feed reader to subscribe to the exception logs of your application.


Scott Tamosunas May 07, 2008 at 21:06

Thanks Ryan for the excellent railscast, as always.

I am getting an exception when I try to protect the logged_exceptions behind an admin authentication (I am using restful_authentication as well):

/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:478:in `const_missing': uninitialized constant Rails::Initializer::AuthenticationSystem (NameError)


Aleksandr May 11, 2008 at 14:34

When I try to download the "exception_logger Plugin [ryanb fork]" from GitHub - the archive doesn't have all the files.

Add your comment:

(required)

(not displayed)

(SKIP THIS ONE)


(required)

subscribe:
sponsored by:
if you want to help:
required:
Get Quicktime Player