#104 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:
- mp4Full Size H.264 Video (17 MB)
- m4vSmaller H.264 Video (10.4 MB)
- webmFull Size VP8 Video (27.6 MB)
- ogvFull Size Theora Video (26.9 MB)
Maybe its a cool idea to use jabber (aka xmpp) for exeption notification to the admin.
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!
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.
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)!
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.
@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.
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.
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
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.
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!
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.
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.
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)
When I try to download the "exception_logger Plugin [ryanb fork]" from GitHub - the archive doesn't have all the files.
Hi, Im getting this error when running script/generate exception_migration
Does anyone have an idea of what's going on?
/vendor/plugins/exception_logger/init.rb:3:in `load_plugin': undefined method `view_paths=' for LoggedExceptionsController:Class (NoMethodError)
Having trouble adding authentication to the exception_logger controller? See:
http://blog.lawrencepit.com/2008/05/07/recording-rails-exceptions/
All installed great, no probs there - but it doesn't log 404 errors. Do you need to hook something in so the exception logger knows about them?
Same problem as Rob, it's not logging any errors.
For Windows Users:
Download and install Git program.
http://code.google.com/p/msysgit/
Then follow run commands above.
I'm trying to get this to work with Rails 2.1 and when run it locally following your instructions here, it works beautifully. However when I get it up on the server and try to start my mongrels I get 1/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:492:in `const_missing': uninitialized constant ApplicationController::ExceptionLoggable (NameError).
I'm not sure why it's not working. In my production.rb file I put what the README said, but it doesn't seem to find the EsceptionLoggable. Is there any more gem requirements besides will_paginate?
I had a lot of trouble getting this working as well. To have a bit more control over what was being logged, I merged the model, helper and controller from the plugin into my actual app. I placed the controller behind my admin auth so it inherited the security settings automatically. I also disregarded the exception_loggable.rb file and added a protected method in the application.rb file. Here's how it looks:
protected
def log_error(exception)
super(exception)
begin
LoggedException.create_from_exception(controller_name, action_name, request, exception)
rescue => e
puts "EXCEPTION: #{e.message}"
logger.error(e)
end
end
I am sure this is not the cleanest way to do it, but it does cut a lot of the fat away from the meat.
I was having some issues with Rails 2.1 as well. When the errors were logged, I could not click the link to see the detail. Nothing happened. FireBug was showing me the output as RJS coming back but nothing happened. I followed Antonio Reina's suggestion above to add:
accepts.js { login_required_without_basic }
to my environments/production.rb file and that did the trick. However, I had already installed the RedCloth gem earlier but that would have mattered as well.
bummer that the git stuff doesn't play well with svn.
I have made a fork of the plugin for jQuery support:
http://github.com/fguillen/exception_logger_jquery/tree/master
I have made just monkey testing.. so I don't know if every thing is correct :)
f.
I get a $.ajax() error when the plugin calls prototype.js.
If you use one of the exception notification plugins mentioned in this episode, but want to receive SMS or phone call alerts instead of email, take a look at PagerDuty (pagerduty.com). It sends automated phone calls or SMS messages in response to any email based trigger. It also lets you route the alerts to different people depending on the day-of-the-week, etc.
Thanks for article. It's very interesting.
Today I've rewritten this plugin as a Gem for Rails3.
For more details checkout:
http://rubygems.org/gems/exception_logger
and
http://github.com/QuBiT/exception_logger
And it works ;)
Enjoy and have fun :)
Nice blog here. Can you set up a notifictaion system with any production site.