Klaxon is a library designed to simply the task of notifying interested parties about your site's operation. You may already be tracking errors through New Relic, but not all errors are created equal -- there are probably parts of your site where an exception occuring is significantly more of a problem than a bored URL surfer visiting random links and throwing 404s. Klaxon can help you be informed when these parts of your site break, or when important events happen.
Currently, Klaxon works only in Rails 3, and supports notification via email.
Add Klaxon to your Gemfile:
gem 'klaxon'
Update your bundle:
bundle install
Use the provided Rake task to generate the migration and model needed by Klaxon. (Angry at the lack of normalization? Install lookup_by and rewrite the migration and model to use it; Klaxon won't even notice.)
rake klaxon:install
Lastly, configure Klaxon to be useful. Create an initializer in config/initializers/klaxon.rb
that looks something like this:
Klaxon.configure do |c| c.from_address = 'me@mysite.com' c.notify 'you@gmail.com', :of => { :category => /user_registrations/ }, :by => :email c.notify ['you@gmail.com', 'sales@mysite.com'], :of => { :category => /new_sales/ } # N.B. 'email' is the default nofifier. c.notify 'ops@mysite.com', :of => { :severity => /critical/ } # Values in the :of hash should be regexes. end
In anywhere you want to send yourself a notification:
Klaxon.notify :category => :user_registrations, :message => "User #{user.name} registered at #{Time.now}!"
If you want to sound the alarm:
begin # ... rescue => e Klaxon.raise_alert e, :category => :user_registrations, :severity => :critical, :message => "An error occurred when a user tried to sign up!" end
In any code you want to watch for explosions:
Klaxon.watch! :category => :important_stuff, :severity => :critical, :message => "Error doing important stuff!" do Important::Stuff.do! end