0.01
No commit activity in last 3 years
No release in over 3 years
Store exceptions in local datbase using Hoptoad API
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0.8.7
>= 1.4.3.1
>= 2.11.3

Runtime

 Project Readme

This pluging works with Rails 3

This plugin works with Rails 3. Please follow the instruction mentioned here . If you have any problem then please create an issue . Also note that all the Rails 3 work is happening in a branch called rails3_gem if you want to look at source code. The master branch is for Rails 2.x work.

Exception2db

I love hoptoad. I especially like the ability to catch exceptions in rake tasks and have those exceptions logged at hoptoad using hoptoad_notifier.

Currently I am working on a government project where hoptoad can’t be used. Rather than writing code that captures all the information about exception, I am letting hoptoad_notifier do all the heavy lifting.

Instead of sending the information to hoptoad this plugin ensures that information is written to a database.

This plugin has been tested with Rails 2.3.5 .

Installing the plugin

Open config/environment.rb and add following line.

config.gem 'hoptoad_notifier'

Install hoptoad_notifier gem by executing

sudo rake gems:install

vendor gem by executing rake gems:unpack GEM=hoptoad_notifier .

Install exception2db plugin

ruby script/plugin install git://github.com/neerajdotname/exception2db.git

Create an empty exception2db.rb file

touch config/initializers/exception2db.rb

Add following text to config/initializers/exception2db.rb file

HoptoadNotifier.configure do |config|
end

module HoptoadNotifier
  def self.send_notice(data)
    Exception2db.create(:exception => data.to_xml)
  end
end

Generate migration

ruby script/generate migration add_exception2db_table

Open the migration file and add following text

class AddException2dbTable < ActiveRecord::Migration
  
  def self.up
    create_table :exception2dbs do |t|
      t.text :exception, :null => false

      t.datetime :created_at, :null => false
    end
  end

  def self.down
    drop_table :exception2dbs
  end

end

Run migration

rake db:migrate

How to use it

Whenever there is an exception that exception will be logged to database. Remember all the hoptoad rules apply. It means no excpetion will be logged in development environment.

To view exceptions visit http://localhost:3000/exception2db .

In order to test this feature first add following line in application_controller.rb .

def local_request?
 false
end

Then start the server in non development environment. Once again please start your server in production
or some other environment. Exceptions in development mode are ignored by hoptoad.

Go to a url that raises exception.

Then visit http://localhost:3000/exception2db . If you are not seeing not authorized message then read the next section.

If you are not seeing the logging of exception then please read this article .

Configuring security

By default no security check is performed while visiting http://localhost:3000/exception2db in development mode. In other environment a security check is done. At the bottom of config/initializers/exception2db.rb add something like this to configure security settings.

Exception2dbConfig.set = {
  :is_allowed_to_view => lambda {|controller| controller.send('admin_logged_in?') }
}

Above code assumes that you have admin_logged_in? method defined in application_controller.rb . The is_allowed_to_view key accepts a proc and controller is provided to you. So you can call any controller method.

How to run tests for this plugin

Running rspec tests

Stand in the current directory and run following command. I assume that you have rspec already installed.

spec spec

Running cucumber test

Stand in the current directory and run following command. I assume you have cucumber already installed.

cucumber

Copyright © 2010 neerajdotname, released under the MIT license