Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

enhance readme docs

git-svn-id: http://svn.techno-weenie.net/projects/plugins/exception_logger@1299 567b1171-46fb-0310-a4c9-b4bef9110e78
  • Loading branch information...
commit 89fee3e9213d3fc6e100e7e9ef435d9dc6ed7d6d 1 parent d2b1087
technoweenie authored
View
36 README
@@ -7,4 +7,38 @@ First you need to generate the migration:
./script/generate exception_migration
-After that, visit /logged_exceptions in your application to manage the exceptions.
+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:
+
+ render_404(exception) - Shows the 404 template.
+
+ render_500(exception) - Shows the 500 template.
+
+ log_exception(exception) - Logs the actual exception in the database.
+
+ rescue_action_in_public(exception) - Does not log these exceptions: ActiveRecord::RecordNotFound, ActionController::UnknownController, ActionController::UnknownAction
+
+After that, visit /logged_exceptions in your application to manage the exceptions.
+
+It's understandable that you may want to require authentication. Add this to your config/environments/production.rb:
+
+ # config/environments/production.rb
+ config.after_initialize do
+ require 'application' unless Object.const_defined?(:ApplicationController)
+ LoggedExceptionsController.class_eval do
+ before_filter :login_required
+ protected
+ # only allow admins
+ # this obviously depends on how your auth system works
+ def authorized?
+ current_user.is_a?(Admin)
+ end
+ end
+ end
+
+The exact code of course depends on the specific needs of your application.
+
+CREDITS
+
+Jamis Buck - original exception_notification plugin
+Rick Olson - model/controller code
+Josh Goebel - design
View
2  init.rb
@@ -1 +1 @@
-# Include hook code here
+LoggedExceptionsController.template_root = File.join(directory, 'views')
View
1  install.rb
@@ -1,2 +1 @@
-# Install hook code here
puts IO.read(File.join(File.dirname(__FILE__), 'README'))
View
28 lib/exception_loggable.rb
@@ -53,14 +53,14 @@ def local_request?
!self.class.local_addresses.detect { |addr| addr.include?(remote) }.nil?
end
- def render_404
+ def render_404(exception)
respond_to do |type|
type.html { render :file => "#{RAILS_ROOT}/public/404.html", :status => "404 Not Found" }
type.all { render :nothing => true, :status => "404 Not Found" }
end
end
- def render_500
+ def render_500(exception)
respond_to do |type|
type.html { render :file => "#{RAILS_ROOT}/public/500.html", :status => "500 Error" }
type.all { render :nothing => true, :status => "500 Error" }
@@ -70,20 +70,22 @@ def render_500
def rescue_action_in_public(exception)
case exception
when ActiveRecord::RecordNotFound, ActionController::UnknownController, ActionController::UnknownAction
- render_404
+ render_404(exception)
else
- render_500
-
- deliverer = self.class.exception_data
- data = case deliverer
- when nil then {}
- when Symbol then send(deliverer)
- when Proc then deliverer.call(self)
- end
-
- LoggedException.create_from_exception(self, exception)
+ render_500(exception)
+ log_exception(exception)
end
end
+ def log_exception(exception)
+ deliverer = self.class.exception_data
+ data = case deliverer
+ when nil then {}
+ when Symbol then send(deliverer)
+ when Proc then deliverer.call(self)
+ end
+
+ LoggedException.create_from_exception(self, exception)
+ end
end
View
1  lib/logged_exceptions_controller.rb
@@ -1,5 +1,4 @@
class LoggedExceptionsController < ActionController::Base
- self.template_root = File.join(RAILS_ROOT, 'vendor/plugins/exception_logger/views')
layout nil
def index
Please sign in to comment.
Something went wrong with that request. Please try again.