r3_exception_logger 0.1.10 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. data/History.txt +75 -0
  2. data/LICENSE +20 -0
  3. data/README.old +107 -0
  4. data/README.rdoc +154 -0
  5. data/Rakefile +66 -0
  6. data/VERSION.yml +5 -0
  7. data/app/controllers/logged_exceptions_controller.rb +86 -0
  8. data/app/helpers/logged_exceptions_helper.rb +40 -0
  9. data/app/models/logged_exception.rb +79 -0
  10. data/app/views/layouts/logged_exceptions.html.erb +19 -0
  11. data/app/views/logged_exceptions/_exceptions.html.erb +31 -0
  12. data/app/views/logged_exceptions/_feed.html.erb +3 -0
  13. data/app/views/logged_exceptions/_show.html.erb +23 -0
  14. data/app/views/logged_exceptions/destroy.js.erb +2 -0
  15. data/app/views/logged_exceptions/destroy_all.js.erb +2 -0
  16. data/app/views/logged_exceptions/feed.rss.builder +20 -0
  17. data/app/views/logged_exceptions/index.html.erb +46 -0
  18. data/app/views/logged_exceptions/index.js.erb +2 -0
  19. data/app/views/logged_exceptions/query.js.erb +2 -0
  20. data/app/views/logged_exceptions/show.html.erb +8 -0
  21. data/app/views/logged_exceptions/show.js.erb +2 -0
  22. data/config/initializers/date_formats.rb +5 -0
  23. data/config/locales/en.yml +16 -0
  24. data/config/routes.rb +11 -0
  25. data/exception_logger.gemspec +23 -0
  26. data/public/javascripts/exception_logger.js +69 -0
  27. data/public/stylesheets/exception_logger.css +325 -0
  28. data/r3_exception_logger-0.1.10.gem +0 -0
  29. data/test/controllers/logged_exceptions_controller_test.rb +196 -0
  30. data/test/models/logged_exception_test.rb +39 -0
  31. data/test/rails_root/Gemfile +52 -0
  32. data/test/rails_root/Gemfile.lock +146 -0
  33. data/test/rails_root/app/controllers/application_controller.rb +5 -0
  34. data/test/rails_root/test/factories/exception_logger.rb +142 -0
  35. data/test/test_helper.rb +10 -0
  36. metadata +36 -1
data/History.txt ADDED
@@ -0,0 +1,75 @@
1
+ == 0.1.6 (2010-08-24)
2
+
3
+ === New
4
+
5
+ * Generator: exception_logger:stylescripts
6
+ ** copies the stylesheet for the exception logger to the public dir
7
+ ** copies the javascript for the exception logger to the public dir
8
+
9
+ === Changes
10
+
11
+ * Generator: exception_migration renamed to exception_logger:migration
12
+
13
+ === Testing
14
+
15
+ * Create Rails Test App at test/rails_root on demand
16
+ ** just store needed files and create the other by the rails generator
17
+ * Create Tests for logged_exception (Model)
18
+ * Create Tests for logged_exceptions_controller (Controller)
19
+ ** Added Tests for GET requests
20
+ ** Added Tests for XHR requests
21
+
22
+ === Optimization
23
+
24
+ * Do not require RedCloth (fallback to simple_format if RedCloth not available)
25
+
26
+ == 0.1.5 (2010-08-17)
27
+
28
+ === New
29
+
30
+ * Gem: Post Installer Infos
31
+
32
+ === Changes
33
+
34
+ * remove unmaintained code to send emails
35
+ ** use http://github.com/rails/exception_notification instead.
36
+ ** instructions added to the readme
37
+ * layout file for index and show
38
+
39
+ === Migration
40
+
41
+ * adapt class find methods to use new syntax
42
+
43
+ == 0.1.4 (2010-08-15)
44
+
45
+ === Optimization
46
+
47
+ * 'query' function now uses the new rails api (ActiveRelation and Scopes)
48
+
49
+ === Migration
50
+
51
+ * 'Delete Visible' link now does what it was intended to do (again).
52
+
53
+ == 0.1.3 (2010-08-14)
54
+
55
+ === Migration
56
+
57
+ * pagination links now work w/ and w/o javascript (again).
58
+
59
+ == 0.1.2 (2010-08-14)
60
+
61
+ === Bugfixes
62
+ * wrong path of rake tasks file solved
63
+
64
+ == 0.1.1 (2010-08-14)
65
+
66
+ === Migration
67
+ * Raketasks (no one defined yet, but it is again possible to define one.)
68
+ * Generator (Fix the exception_migration Generator from the plugin to be available through the gem)
69
+
70
+ == 0.1.0 (2010-08-14)
71
+
72
+ * First Released Version of Gem on RubyGems.org
73
+
74
+ === Migration
75
+ * Many changes to migrate the plugin to a gem for Rails3
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Roland Guem
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.old ADDED
@@ -0,0 +1,107 @@
1
+ ExceptionLogger
2
+ ===============
3
+
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
+
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
+
20
+ Now add a new route to your routes.rb:
21
+
22
+ map.connect "logged_exceptions/:action/:id", :controller => "logged_exceptions"
23
+
24
+ If you want the RSS Feed mapping, add this right after:
25
+
26
+ map.connect "logged_exceptions/:action.:format", :controller => "logged_exceptions"
27
+
28
+ After that, visit /logged_exceptions in your application to manage the exceptions.
29
+
30
+ Email notify config:
31
+ LoggedExceptionsMailer.mailer_config.update( {
32
+ :subject => 'Exception',
33
+ :recipients => "me@gmail.com",
34
+ :from => 'system@domain.com',
35
+ :link => 'http://domain.com',
36
+ :deliver => true # dispatching on
37
+ })
38
+
39
+ It's understandable that you may want to require authentication. You can do this by creating your own controller extending your ApplicationController (thereby leveraging all the existing authorization rules you may have) and include the ExceptionLoggableControllerMixin module. For example:
40
+
41
+ class LoggedExceptionsController < ApplicationController
42
+ include ExceptionLoggableControllerMixin
43
+ self.application_name = "My Application Name" # this will show up in the title of the Rss feed
44
+
45
+ # add your regular permission checking here, e.g.:
46
+ protected
47
+ # only allow admins
48
+ # this obviously depends on how your auth system works
49
+ def authorized?
50
+ current_user.is_a?(Admin)
51
+ end
52
+
53
+ # assume app's login required doesn't use http basic
54
+ def login_required_with_basic
55
+ respond_to do |accepts|
56
+ # alias_method_chain will alias the app's login_required to login_required_without_basic
57
+ accepts.html { login_required_without_basic }
58
+
59
+ # access_denied_with_basic_auth is defined in ExceptionLoggableControllerMixin
60
+ # get_auth_data returns back the user/password pair
61
+ accepts.rss do
62
+ access_denied_with_basic_auth unless self.current_user = User.authenticate(*get_auth_data)
63
+ end
64
+ end
65
+ end
66
+
67
+ alias_method_chain :login_required, :basic
68
+ end
69
+
70
+ The exact code of course depends on the specific needs of your application.
71
+
72
+ You can use ActionController::Base.filter_parameter_logging in the LoggedExceptionsController.
73
+ In the code given above, do something like
74
+
75
+ LoggedExceptionsController.class_eval do
76
+ filter_parameter_logging :password
77
+ end
78
+
79
+ When viewing a logged exception, parameters whose name has "password" as a substring
80
+ will show their values as "[FILTERED]". There is a link to toggle this filtering, in
81
+ case you really must have a look.
82
+
83
+ Note that GET parameters will still be shown unfiltered within the logged URL.
84
+
85
+ Catching exceptions from rake tasks:
86
+ desc ''
87
+ task :bar => :environment do |rake_task|
88
+ begin
89
+ raise Exception, ''
90
+ rescue Exception => e
91
+ LoggedExceptionRake.save_exception e, rake_task, ENV
92
+ end
93
+ end
94
+
95
+ CREDITS
96
+
97
+ Jamis Buck - original exception_notification plugin
98
+ Rick Olson - model/controller code
99
+ Josh Goebel - design
100
+
101
+ UPDATES
102
+
103
+ Chris Wanstrath - use will_paginate
104
+ Henrik Nyh (DanceJam) - log exceptions in dev, linkable exceptions, parameter filtering etc
105
+ Zhurbiy Oleg (Ol.keene) - exception notify by email, exceptions catching from rake tasks, will_paginate fix
106
+ David Rubin - Merged in different peoples branches. Fixed minor bugs and cleaned up the code.
107
+ Jason Knight - Pagination support, built on/inspired by Ryanb's willpaginate support.
data/README.rdoc ADDED
@@ -0,0 +1,154 @@
1
+ = Exception Logger for Rails3
2
+
3
+ You liked the exception logger from http://github.com/defunkt/exception_logger for Rails2?
4
+
5
+ You want to have the same functionallity using Rails3?
6
+
7
+ You want to upgrade your Rails2 application and the old plugin breaks?
8
+
9
+ You ...
10
+
11
+ Then just use the exception_logger gem instead and tell your friends to do the same ;)
12
+
13
+ == Hosted on RubyGems.org
14
+
15
+ This gem is hosted on RubyGems.org: http://rubygems.org/gems/exception_logger
16
+
17
+ == Install
18
+
19
+ Inside your Gemfile:
20
+
21
+ gem "exception_logger", :require => "exception_logger"
22
+
23
+ and then run:
24
+
25
+ bundle install
26
+
27
+ === Gem Dependencies
28
+
29
+ Please check if all those requirements are satisfied on your environment.
30
+
31
+ * i18n >= 0.4.1
32
+ * meta_where >= 0.5.2 # (used to avoid SQL inside the CODE)
33
+ * will_paginate >= 3.0.pre2 # (used for pagination)
34
+ * rails >= 3.0.0
35
+
36
+ === Inside your ApplicationController:
37
+
38
+ include ExceptionLogger::ExceptionLoggable # loades the module
39
+ rescue_from Exception, :with => :log_exception_handler # tells rails to forward the 'Exception' (you can change the type) to the handler of the module
40
+
41
+ == Generators
42
+
43
+ === Database Setup
44
+
45
+ Use
46
+
47
+ rails g exception_logger:migration
48
+
49
+ This will create a database migration
50
+
51
+ TIMESTAMP_add_exception_table.rb
52
+
53
+ inside db/migrations
54
+
55
+ === Stylesheet and Javascript
56
+
57
+ You can copy the stylesheet and javascript to your applications public directory by using
58
+
59
+ rails g exception_logger:stylescripts
60
+
61
+ This allows you to customize those files.
62
+
63
+ This will be also necessary if you use a webserver ( e.g. passenger+nginx ) in front of rails which does the static file handling for you.
64
+
65
+ == Routing
66
+
67
+ The gem is preconfigured to extend your routes automatically. You can access the logged exceptions by pointing to "/logged_exceptions" inside your application.
68
+
69
+ You can use the rake tasks
70
+
71
+ rake routes
72
+
73
+ to see and check the routes.
74
+
75
+ == Exception Notification
76
+
77
+ === by Email
78
+
79
+ Rails directly provides a plugin called "Exception Notification" ( http://github.com/rails/exception_notification ).
80
+
81
+ Just download the plugin and follow the usage instructions from the README file ( http://github.com/rails/exception_notification/blob/master/README ) and add this code to one of your initializer files
82
+
83
+ # Example: put this to config/initializers/exception_notification.rb
84
+ Whatever::Application.config.middleware.use ExceptionNotifier,
85
+ :email_prefix => "[Whatever] ",
86
+ :sender_address => %{"notifier" <notifier@example.com>},
87
+ :exception_recipients => %w{exceptions@example.com}
88
+
89
+ Restart your server and you are done. (Don't forget to setup your email settings inside your environment files.)
90
+
91
+ == Authentication
92
+
93
+ If you want, and believe me you want that, you can add the following lines to your environment to enable Authentication
94
+
95
+ Example uses the declarative_authorization gem
96
+
97
+ in config/environment/production.rb:
98
+
99
+ config.after_initialize do
100
+ LoggedExceptionsController.class_eval do
101
+ # include any custom auth modules you need
102
+ # (declarative authorization gem used)
103
+ filter_resource_access
104
+ # just add any code you want to be included in the controller ;)
105
+ # optional, sets the application name for the rss feeds
106
+ self.application_name = "Your Application Name"
107
+ end
108
+ end
109
+
110
+ and (if you use declarative_authorization) add this to your authorization_rules.rb file:
111
+
112
+ role :admin do
113
+ has_permission_on :logged_exceptions, :to => :manage
114
+ ...
115
+
116
+ == Upgrading from the old plugin
117
+
118
+ If you have used the exception_logger plugin for your rails2 application and want to migrate to rails 3 then:
119
+
120
+ * Remove the old plugin (just delete the vendor/plugins/exception_logger folder)
121
+ * Install the new gem version (see Install)
122
+ * DONE. (if I forgot something, then let me know.)
123
+
124
+ == Legacy
125
+
126
+ For more and older details read the README.old File.
127
+
128
+ == Testing & Development
129
+
130
+ Testing should always start before the actual development.
131
+
132
+ You can test this gem very easily. Just run:
133
+
134
+ rake test:basic
135
+
136
+ from the console of the cloned github repository of the exception logger.
137
+
138
+ This rake task will create a rails app inside the test directory called rails_root and will install the exception logger and migrate the database of that application just in time.
139
+
140
+ The generator which generates the rails app in your test directory will skip over every existing file, hence if you want to customize a file, then just add/create it.
141
+
142
+ == Note on Patches/Pull Requests
143
+
144
+ * Fork the project.
145
+ * Make your feature addition or bug fix.
146
+ * Add tests for it. This is important so I don't break it in a
147
+ future version unintentionally.
148
+ * Commit, do not mess with rakefile, version, or history.
149
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
150
+ * Send me a pull request. Bonus points for topic branches.
151
+
152
+ == Copyright
153
+
154
+ Copyright (c) 2010 Roland Guem. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,66 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ begin
4
+ require 'jeweler'
5
+ Jeweler::Tasks.new do |gem|
6
+ gem.name = "exception_logger"
7
+ gem.summary = "Exception Logger for Rails 3"
8
+ gem.description = "Logs exceptions inside a database table. Now available as gem for Rails3 (previously a plugin for Rails2)"
9
+ gem.email = "roland.guem@gmail.com"
10
+ gem.homepage = "http://github.com/QuBiT/exception_logger"
11
+ gem.authors = ["Roland Guem"]
12
+ gem.files = Dir["{lib}/**/*", "{app}/**/*", "{config}/**/*", "{public}/**/*"]
13
+ gem.test_files = Dir["{test}/**/*"]
14
+ gem.add_dependency 'rails', '>=3.0.0'
15
+ gem.add_dependency "kaminari"
16
+ gem.add_dependency "squeel"
17
+ gem.add_dependency "i18n", ">= 0.4.1"
18
+ gem.add_development_dependency "shoulda", ">= 2.11.3"
19
+ gem.extra_rdoc_files = ["LICENSE","README.rdoc"]
20
+ gem.post_install_message = %q{
21
+ _()_()_()_()_()_()_()_()_()_()_()_()_()_()_()_()_()_()_()_()_()_()_()_()_()_()_
22
+ Thank you for installing exception_logger.
23
+ Please be sure to read the README and HISTORY on
24
+ http://github.com/QuBiT/exception_logger
25
+ for important information about this release. Happy logging!
26
+ _()_()_()_()_()_()_()_()_()_()_()_()_()_()_()_()_()_()_()_()_()_()_()_()_()_()_
27
+ }
28
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
29
+ end
30
+ Jeweler::GemcutterTasks.new
31
+ rescue LoadError
32
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
33
+ end
34
+
35
+ ENV['BUNDLE_GEMFILE'] = File.dirname(__FILE__) + '/test/rails_root/Gemfile'
36
+
37
+ #require 'rake'
38
+ require 'rake/testtask'
39
+ require 'cucumber/rake/task'
40
+ require 'spec/rake/spectask'
41
+
42
+ namespace :test do
43
+ Rake::TestTask.new(:basic => %w(test:generator:rails_setup test:generator:exception_migration)) do |task|
44
+ task.libs << "lib"
45
+ task.libs << "test"
46
+ task.pattern = "test/**/*_test.rb"
47
+ #task.verbose = false
48
+ end
49
+
50
+ Cucumber::Rake::Task.new(:features) do |t|
51
+ t.cucumber_opts = "--format progress"
52
+ t.profile = 'features'
53
+ end
54
+
55
+ namespace :generator do
56
+
57
+ task :rails_setup do
58
+ system "cd test && rails new rails_root --skip"
59
+ end
60
+
61
+ task :exception_migration do
62
+ system "cd test/rails_root && bundle install && ./script/rails generate exception_logger:migration && rake db:migrate db:test:prepare"
63
+ end
64
+ end
65
+
66
+ end
data/VERSION.yml ADDED
@@ -0,0 +1,5 @@
1
+ ---
2
+ :patch: 10
3
+ :major: 0
4
+ :build:
5
+ :minor: 1
@@ -0,0 +1,86 @@
1
+ class LoggedExceptionsController < ApplicationController
2
+
3
+ cattr_accessor :application_name
4
+
5
+ #ApplicationController.class_eval do
6
+ # rescue_from Exception, :with => :log_exception_handler
7
+ #end
8
+
9
+ def index
10
+ @exception_names = LoggedException.class_names
11
+ @controller_actions = LoggedException.controller_actions
12
+ query
13
+ end
14
+
15
+ def query
16
+ exceptions = LoggedException.sorted
17
+ unless params[:id].blank?
18
+ exceptions = exceptions.where(:id => params[:id])
19
+ end
20
+ unless params[:query].blank?
21
+ exceptions = exceptions.message_like(params[:query])
22
+ end
23
+ unless params[:date_ranges_filter].blank?
24
+ exceptions = exceptions.days_old(params[:date_ranges_filter])
25
+ end
26
+ unless params[:exception_names_filter].blank?
27
+ exceptions = exceptions.by_exception_class(params[:exception_names_filter])
28
+ end
29
+ unless params[:controller_actions_filter].blank?
30
+ c_a_params = params[:controller_actions_filter].split('/')
31
+ controller_filter = c_a_params.first.underscore
32
+ action_filter = c_a_params.last.downcase
33
+ exceptions = exceptions.by_controller(controller_filter)
34
+ exceptions = exceptions.by_action(action_filter)
35
+ end
36
+ @exceptions = exceptions.page(params[:page]).per(30)
37
+
38
+ respond_to do |format|
39
+ format.html { redirect_to :action => 'index' unless action_name == 'index' }
40
+ format.js
41
+ end
42
+ end
43
+
44
+ def feed
45
+ @exceptions = LoggedException.all
46
+
47
+ respond_to do |format|
48
+ format.rss { render :layout => false }
49
+ end
50
+ end
51
+
52
+ def show
53
+ @exception = LoggedException.where(:id => params[:id]).first
54
+
55
+ respond_to do |format|
56
+ format.js
57
+ format.html
58
+ end
59
+ end
60
+
61
+ def destroy
62
+ @exception = LoggedException.where(:id => params[:id]).first
63
+ @exception.destroy
64
+ end
65
+
66
+ def destroy_all
67
+ LoggedException.delete_all(:id => params[:ids]) unless params[:ids].blank?
68
+ query
69
+ end
70
+
71
+ private
72
+ def access_denied_with_basic_auth
73
+ headers["Status"] = "Unauthorized"
74
+ headers["WWW-Authenticate"] = %(Basic realm="Web Password")
75
+ render :text => "Could't authenticate you", :status => '401 Unauthorized'
76
+ end
77
+
78
+ @@http_auth_headers = %w(X-HTTP_AUTHORIZATION HTTP_AUTHORIZATION Authorization)
79
+ # gets BASIC auth info
80
+ def get_auth_data
81
+ auth_key = @@http_auth_headers.detect { |h| request.env.has_key?(h) }
82
+ auth_data = request.env[auth_key].to_s.split unless auth_key.blank?
83
+ return auth_data && auth_data[0] == 'Basic' ? Base64.decode64(auth_data[1]).split(':')[0..1] : [nil, nil]
84
+ end
85
+ end
86
+