public
Clone URL: git://github.com/defunkt/exception_logger.git
Search Repo:
enhance readme docs

git-svn-id: 
http://svn.techno-weenie.net/projects/plugins/exception_logger@1299 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Sun Jul 02 06:55:40 -0700 2006
commit  89fee3e9213d3fc6e100e7e9ef435d9dc6ed7d6d
tree    0346f7a5d68945e3266000eedd079611604ceaba
parent  d2b108761e91740a0cbe2b70fa50aa94c1dadc6e
0
...
7
8
9
 
 
 
 
 
 
 
 
 
 
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
0
@@ -7,5 +7,39 @@
0
 
0
   ./script/generate exception_migration
0
 
0
+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:
0
+
0
+ render_404(exception) - Shows the 404 template.
0
+
0
+ render_500(exception) - Shows the 500 template.
0
+
0
+ log_exception(exception) - Logs the actual exception in the database.
0
+
0
+ rescue_action_in_public(exception) - Does not log these exceptions: ActiveRecord::RecordNotFound, ActionController::UnknownController, ActionController::UnknownAction
0
+
0
 After that, visit /logged_exceptions in your application to manage the exceptions.
0
+
0
+It's understandable that you may want to require authentication. Add this to your config/environments/production.rb:
0
+
0
+ # config/environments/production.rb
0
+ config.after_initialize do
0
+ require 'application' unless Object.const_defined?(:ApplicationController)
0
+ LoggedExceptionsController.class_eval do
0
+ before_filter :login_required
0
+ protected
0
+ # only allow admins
0
+ # this obviously depends on how your auth system works
0
+ def authorized?
0
+ current_user.is_a?(Admin)
0
+ end
0
+ end
0
+ end
0
+
0
+The exact code of course depends on the specific needs of your application.
0
+
0
+CREDITS
0
+
0
+Jamis Buck - original exception_notification plugin
0
+Rick Olson - model/controller code
0
+Josh Goebel - design
...
1
 
...
 
1
0
@@ -1,2 +1,2 @@
0
-# Include hook code here
0
+LoggedExceptionsController.template_root = File.join(directory, 'views')
...
1
2
...
 
1
0
@@ -1,3 +1,2 @@
0
-# Install hook code here
0
 puts IO.read(File.join(File.dirname(__FILE__), 'README'))
...
53
54
55
56
 
57
58
59
60
61
62
63
 
64
65
66
67
68
...
70
71
72
73
 
74
75
76
77
78
79
80
81
82
83
84
85
 
 
86
87
88
 
 
 
 
 
 
 
 
 
 
89
...
53
54
55
 
56
57
58
59
60
61
62
 
63
64
65
66
67
68
...
70
71
72
 
73
74
75
 
 
 
 
 
 
 
 
 
 
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
0
@@ -53,14 +53,14 @@
0
     !self.class.local_addresses.detect { |addr| addr.include?(remote) }.nil?
0
   end
0
 
0
- def render_404
0
+ def render_404(exception)
0
     respond_to do |type|
0
       type.html { render :file => "#{RAILS_ROOT}/public/404.html", :status => "404 Not Found" }
0
       type.all { render :nothing => true, :status => "404 Not Found" }
0
     end
0
   end
0
 
0
- def render_500
0
+ def render_500(exception)
0
     respond_to do |type|
0
       type.html { render :file => "#{RAILS_ROOT}/public/500.html", :status => "500 Error" }
0
       type.all { render :nothing => true, :status => "500 Error" }
0
0
0
@@ -70,21 +70,23 @@
0
   def rescue_action_in_public(exception)
0
     case exception
0
       when ActiveRecord::RecordNotFound, ActionController::UnknownController, ActionController::UnknownAction
0
- render_404
0
+ render_404(exception)
0
 
0
       else
0
- render_500
0
-
0
- deliverer = self.class.exception_data
0
- data = case deliverer
0
- when nil then {}
0
- when Symbol then send(deliverer)
0
- when Proc then deliverer.call(self)
0
- end
0
-
0
- LoggedException.create_from_exception(self, exception)
0
+ render_500(exception)
0
+ log_exception(exception)
0
     end
0
   end
0
 
0
+ def log_exception(exception)
0
+ deliverer = self.class.exception_data
0
+ data = case deliverer
0
+ when nil then {}
0
+ when Symbol then send(deliverer)
0
+ when Proc then deliverer.call(self)
0
+ end
0
+
0
+ LoggedException.create_from_exception(self, exception)
0
+ end
0
 end
...
1
2
3
4
5
...
1
 
2
3
4
0
@@ -1,5 +1,4 @@
0
 class LoggedExceptionsController < ActionController::Base
0
- self.template_root = File.join(RAILS_ROOT, 'vendor/plugins/exception_logger/views')
0
   layout nil
0
 
0
   def index

Comments

    No one has commented yet.