ryanb / exception_logger forked from defunkt/exception_logger
- Source
- Commits
- Network (32)
- Issues (0)
- Downloads (0)
- Wiki (1)
- Graphs
-
Tree:
c25f64a
exception_logger / README
| e33986d9 » | technoweenie | 2006-06-23 | 1 | ExceptionLogger | |
| 2 | =============== | ||||
| 3 | |||||
| 56b6213b » | technoweenie | 2006-06-23 | 4 | The Exception Logger (forgive the horrible name) logs your Rails exceptions in the database and provides a funky web interface to manage them. | |
| 5 | |||||
| 6 | First you need to generate the migration: | ||||
| 7 | |||||
| 8 | ./script/generate exception_migration | ||||
| 9 | |||||
| 89fee3e9 » | technoweenie | 2006-07-02 | 10 | Next, you'll need to include the ExceptionLoggable module into ApplicationController. Once that's done you might want to modify key methods to customize the logging: | |
| 11 | |||||
| 12 | render_404(exception) - Shows the 404 template. | ||||
| 13 | |||||
| 14 | render_500(exception) - Shows the 500 template. | ||||
| 15 | |||||
| 16 | log_exception(exception) - Logs the actual exception in the database. | ||||
| 17 | |||||
| 18 | rescue_action_in_public(exception) - Does not log these exceptions: ActiveRecord::RecordNotFound, ActionController::UnknownController, ActionController::UnknownAction | ||||
| 19 | |||||
| dacb6ebb » | nicklinnell | 2008-05-01 | 20 | Now add a new route to your routes.rb: | |
| 21 | |||||
| c25f64a9 » | ryanb | 2008-05-04 | 22 | map.connect "logged_exceptions/:action/:id", :controller => "logged_exceptions" | |
| dacb6ebb » | nicklinnell | 2008-05-01 | 23 | ||
| 89fee3e9 » | technoweenie | 2006-07-02 | 24 | After that, visit /logged_exceptions in your application to manage the exceptions. | |
| 25 | |||||
| 26 | It's understandable that you may want to require authentication. Add this to your config/environments/production.rb: | ||||
| 27 | |||||
| 28 | # config/environments/production.rb | ||||
| 29 | config.after_initialize do | ||||
| 30 | require 'application' unless Object.const_defined?(:ApplicationController) | ||||
| 31 | LoggedExceptionsController.class_eval do | ||||
| e2d703cd » | technoweenie | 2006-09-03 | 32 | # set the same session key as the app | |
| 33 | session :session_key => '_beast_session_id' | ||||
| 34 | |||||
| 35 | # include any custom auth modules you need | ||||
| 36 | include AuthenticationSystem | ||||
| 37 | |||||
| 89fee3e9 » | technoweenie | 2006-07-02 | 38 | before_filter :login_required | |
| e2d703cd » | technoweenie | 2006-09-03 | 39 | ||
| 40 | # optional, sets the application name for the rss feeds | ||||
| 41 | self.application_name = "Beast" | ||||
| 42 | |||||
| 89fee3e9 » | technoweenie | 2006-07-02 | 43 | protected | |
| 44 | # only allow admins | ||||
| 45 | # this obviously depends on how your auth system works | ||||
| 46 | def authorized? | ||||
| 47 | current_user.is_a?(Admin) | ||||
| 48 | end | ||||
| e2d703cd » | technoweenie | 2006-09-03 | 49 | ||
| 50 | # assume app's login required doesn't use http basic | ||||
| 51 | def login_required_with_basic | ||||
| 52 | respond_to do |accepts| | ||||
| 53 | # alias_method_chain will alias the app's login_required to login_required_without_basic | ||||
| 54 | accepts.html { login_required_without_basic } | ||||
| 55 | |||||
| 56 | # access_denied_with_basic_auth is defined in LoggedExceptionsController | ||||
| 57 | # get_auth_data returns back the user/password pair | ||||
| 58 | accepts.rss do | ||||
| 59 | access_denied_with_basic_auth unless self.current_user = User.authenticate(*get_auth_data) | ||||
| 60 | end | ||||
| 61 | end | ||||
| 62 | end | ||||
| 63 | |||||
| 64 | alias_method_chain :login_required, :basic | ||||
| 89fee3e9 » | technoweenie | 2006-07-02 | 65 | end | |
| 66 | end | ||||
| 67 | |||||
| 68 | The exact code of course depends on the specific needs of your application. | ||||
| 69 | |||||
| 70 | CREDITS | ||||
| 71 | |||||
| 72 | Jamis Buck - original exception_notification plugin | ||||
| 73 | Rick Olson - model/controller code | ||||
| dacb6ebb » | nicklinnell | 2008-05-01 | 74 | Josh Goebel - design | |
