tartarus 1.0.3 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/.rvmrc +2 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +104 -0
- data/README.rdoc +30 -4
- data/Rakefile +10 -28
- data/{generators → lib/generators}/tartarus/USAGE +4 -3
- data/lib/generators/tartarus/tartarus_generator.rb +36 -0
- data/{generators → lib/generators}/tartarus/templates/app/controllers/exceptions_controller.rb +0 -0
- data/{generators → lib/generators}/tartarus/templates/app/models/logged_exception.rb +0 -0
- data/{generators → lib/generators}/tartarus/templates/app/views/exceptions/_exception.html.erb +0 -0
- data/{generators → lib/generators}/tartarus/templates/app/views/exceptions/details.html.erb +0 -0
- data/{generators → lib/generators}/tartarus/templates/app/views/exceptions/index.html.erb +0 -0
- data/{generators → lib/generators}/tartarus/templates/config/exceptions.yml +0 -0
- data/{generators → lib/generators}/tartarus/templates/db/migrate/add_logged_exceptions.rb +0 -0
- data/{generators → lib/generators}/tartarus/templates/public/javascripts/tartarus.jquery.js +0 -0
- data/{generators → lib/generators}/tartarus/templates/public/stylesheets/tartarus.css +0 -0
- data/{generators → lib/generators}/tartarus/templates/spec/controllers/exceptions_controller_spec.rb +1 -1
- data/{generators → lib/generators}/tartarus/templates/spec/models/logged_exception_spec.rb +0 -0
- data/lib/tartarus.rb +7 -3
- data/lib/tartarus/logger.rb +50 -14
- data/lib/tartarus/notifiers/mail.rb +25 -0
- data/lib/tartarus/rack.rb +23 -0
- data/lib/tartarus/railtie.rb +9 -0
- data/lib/tartarus/version.rb +3 -0
- data/spec/rails_app/.gitignore +4 -0
- data/spec/rails_app/.rspec +1 -0
- data/spec/rails_app/Gemfile +13 -0
- data/spec/rails_app/Gemfile.lock +99 -0
- data/spec/rails_app/README +256 -0
- data/spec/rails_app/Rakefile +7 -0
- data/spec/rails_app/app/controllers/application_controller.rb +3 -0
- data/spec/rails_app/app/controllers/logged_exceptions_controller.rb +31 -0
- data/spec/rails_app/app/helpers/application_helper.rb +2 -0
- data/spec/{rails → rails_app}/app/models/logged_exception.rb +2 -1
- data/spec/rails_app/app/views/layouts/application.html.erb +14 -0
- data/spec/rails_app/app/views/logged_exceptions/_exception.html.erb +14 -0
- data/spec/rails_app/app/views/logged_exceptions/details.html.erb +86 -0
- data/spec/rails_app/app/views/logged_exceptions/index.html.erb +28 -0
- data/spec/rails_app/config.ru +4 -0
- data/spec/rails_app/config/application.rb +42 -0
- data/spec/rails_app/config/boot.rb +13 -0
- data/spec/rails_app/config/database.yml +22 -0
- data/spec/rails_app/config/environment.rb +5 -0
- data/spec/rails_app/config/environments/development.rb +26 -0
- data/spec/rails_app/config/environments/production.rb +49 -0
- data/spec/rails_app/config/environments/test.rb +35 -0
- data/spec/rails_app/config/exceptions.yml +18 -0
- data/spec/{rails → rails_app}/config/initializers/backtrace_silencers.rb +2 -2
- data/spec/{rails → rails_app}/config/initializers/inflections.rb +1 -1
- data/spec/{rails → rails_app}/config/initializers/mime_types.rb +0 -0
- data/spec/rails_app/config/initializers/secret_token.rb +7 -0
- data/spec/rails_app/config/initializers/session_store.rb +8 -0
- data/spec/{rails → rails_app}/config/locales/en.yml +1 -1
- data/spec/rails_app/config/routes.rb +58 -0
- data/spec/rails_app/db/migrate/20101230191040_add_logged_exception_table.rb +19 -0
- data/spec/rails_app/db/schema.rb +28 -0
- data/spec/rails_app/db/seeds.rb +7 -0
- data/spec/rails_app/doc/README_FOR_APP +2 -0
- data/spec/rails_app/lib/tasks/.gitkeep +0 -0
- data/spec/rails_app/public/404.html +26 -0
- data/spec/rails_app/public/422.html +26 -0
- data/spec/rails_app/public/500.html +26 -0
- data/spec/rails_app/public/favicon.ico +0 -0
- data/spec/rails_app/public/images/rails.png +0 -0
- data/spec/rails_app/public/javascripts/application.js +2 -0
- data/spec/rails_app/public/javascripts/controls.js +965 -0
- data/spec/rails_app/public/javascripts/dragdrop.js +974 -0
- data/spec/rails_app/public/javascripts/effects.js +1123 -0
- data/spec/rails_app/public/javascripts/prototype.js +6001 -0
- data/spec/rails_app/public/javascripts/rails.js +175 -0
- data/spec/rails_app/public/javascripts/tartarus.jquery.js +8 -0
- data/spec/rails_app/public/robots.txt +5 -0
- data/spec/rails_app/public/stylesheets/.gitkeep +0 -0
- data/spec/rails_app/public/stylesheets/tartarus.css +26 -0
- data/spec/rails_app/script/rails +6 -0
- data/spec/rails_app/spec/controllers/logged_exceptions_controller_spec.rb +83 -0
- data/spec/rails_app/spec/models/logged_exception_spec.rb +7 -0
- data/spec/rails_app/spec/spec_helper.rb +27 -0
- data/spec/rails_app/vendor/plugins/.gitkeep +0 -0
- data/spec/spec_helper.rb +14 -7
- data/spec/tartarus/logger_spec.rb +51 -23
- data/spec/tartarus_spec.rb +5 -8
- data/tartarus.gemspec +11 -103
- metadata +148 -94
- data/VERSION +0 -1
- data/generators/tartarus/tartarus_generator.rb +0 -50
- data/lib/tartarus/notifier.rb +0 -11
- data/lib/tartarus/rescue.rb +0 -39
- data/rails/init.rb +0 -3
- data/spec/rails/app/controllers/application_controller.rb +0 -10
- data/spec/rails/config/boot.rb +0 -110
- data/spec/rails/config/database.yml +0 -5
- data/spec/rails/config/environment.rb +0 -41
- data/spec/rails/config/environments/development.rb +0 -17
- data/spec/rails/config/environments/production.rb +0 -28
- data/spec/rails/config/environments/test.rb +0 -28
- data/spec/rails/config/exceptions.yml +0 -9
- data/spec/rails/config/initializers/new_rails_defaults.rb +0 -21
- data/spec/rails/config/initializers/session_store.rb +0 -15
- data/spec/rails/config/routes.rb +0 -43
- data/spec/rails/db/test.sqlite3 +0 -0
- data/spec/rcov.opts +0 -3
- data/spec/spec.opts +0 -4
- data/spec/tartarus/rescue_spec.rb +0 -86
- data/views/tartarus_notifier/notification.html.erb +0 -9
data/.gitignore
CHANGED
data/.rvmrc
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
tartarus (2.0.0)
|
|
5
|
+
json (~> 1.4.6)
|
|
6
|
+
will_paginate (~> 3.0.pre2)
|
|
7
|
+
|
|
8
|
+
GEM
|
|
9
|
+
remote: http://rubygems.org/
|
|
10
|
+
specs:
|
|
11
|
+
abstract (1.0.0)
|
|
12
|
+
actionmailer (3.0.0)
|
|
13
|
+
actionpack (= 3.0.0)
|
|
14
|
+
mail (~> 2.2.5)
|
|
15
|
+
actionpack (3.0.0)
|
|
16
|
+
activemodel (= 3.0.0)
|
|
17
|
+
activesupport (= 3.0.0)
|
|
18
|
+
builder (~> 2.1.2)
|
|
19
|
+
erubis (~> 2.6.6)
|
|
20
|
+
i18n (~> 0.4.1)
|
|
21
|
+
rack (~> 1.2.1)
|
|
22
|
+
rack-mount (~> 0.6.12)
|
|
23
|
+
rack-test (~> 0.5.4)
|
|
24
|
+
tzinfo (~> 0.3.23)
|
|
25
|
+
activemodel (3.0.0)
|
|
26
|
+
activesupport (= 3.0.0)
|
|
27
|
+
builder (~> 2.1.2)
|
|
28
|
+
i18n (~> 0.4.1)
|
|
29
|
+
activerecord (3.0.0)
|
|
30
|
+
activemodel (= 3.0.0)
|
|
31
|
+
activesupport (= 3.0.0)
|
|
32
|
+
arel (~> 1.0.0)
|
|
33
|
+
tzinfo (~> 0.3.23)
|
|
34
|
+
activeresource (3.0.0)
|
|
35
|
+
activemodel (= 3.0.0)
|
|
36
|
+
activesupport (= 3.0.0)
|
|
37
|
+
activesupport (3.0.0)
|
|
38
|
+
arel (1.0.1)
|
|
39
|
+
activesupport (~> 3.0.0)
|
|
40
|
+
builder (2.1.2)
|
|
41
|
+
diff-lcs (1.1.2)
|
|
42
|
+
erubis (2.6.6)
|
|
43
|
+
abstract (>= 1.0.0)
|
|
44
|
+
i18n (0.4.2)
|
|
45
|
+
json (1.4.6)
|
|
46
|
+
mail (2.2.13)
|
|
47
|
+
activesupport (>= 2.3.6)
|
|
48
|
+
i18n (>= 0.4.0)
|
|
49
|
+
mime-types (~> 1.16)
|
|
50
|
+
treetop (~> 1.4.8)
|
|
51
|
+
mime-types (1.16)
|
|
52
|
+
polyglot (0.3.1)
|
|
53
|
+
rack (1.2.1)
|
|
54
|
+
rack-mount (0.6.13)
|
|
55
|
+
rack (>= 1.0.0)
|
|
56
|
+
rack-test (0.5.6)
|
|
57
|
+
rack (>= 1.0)
|
|
58
|
+
rails (3.0.0)
|
|
59
|
+
actionmailer (= 3.0.0)
|
|
60
|
+
actionpack (= 3.0.0)
|
|
61
|
+
activerecord (= 3.0.0)
|
|
62
|
+
activeresource (= 3.0.0)
|
|
63
|
+
activesupport (= 3.0.0)
|
|
64
|
+
bundler (~> 1.0.0)
|
|
65
|
+
railties (= 3.0.0)
|
|
66
|
+
railties (3.0.0)
|
|
67
|
+
actionpack (= 3.0.0)
|
|
68
|
+
activesupport (= 3.0.0)
|
|
69
|
+
rake (>= 0.8.4)
|
|
70
|
+
thor (~> 0.14.0)
|
|
71
|
+
rake (0.8.7)
|
|
72
|
+
rcov (0.9.9)
|
|
73
|
+
rspec (2.3.0)
|
|
74
|
+
rspec-core (~> 2.3.0)
|
|
75
|
+
rspec-expectations (~> 2.3.0)
|
|
76
|
+
rspec-mocks (~> 2.3.0)
|
|
77
|
+
rspec-core (2.3.1)
|
|
78
|
+
rspec-expectations (2.3.0)
|
|
79
|
+
diff-lcs (~> 1.1.2)
|
|
80
|
+
rspec-mocks (2.3.0)
|
|
81
|
+
rspec-rails (2.3.1)
|
|
82
|
+
actionpack (~> 3.0)
|
|
83
|
+
activesupport (~> 3.0)
|
|
84
|
+
railties (~> 3.0)
|
|
85
|
+
rspec (~> 2.3.0)
|
|
86
|
+
sqlite3-ruby (1.3.2)
|
|
87
|
+
thor (0.14.6)
|
|
88
|
+
treetop (1.4.9)
|
|
89
|
+
polyglot (>= 0.3.1)
|
|
90
|
+
tzinfo (0.3.23)
|
|
91
|
+
will_paginate (3.0.pre2)
|
|
92
|
+
|
|
93
|
+
PLATFORMS
|
|
94
|
+
ruby
|
|
95
|
+
|
|
96
|
+
DEPENDENCIES
|
|
97
|
+
json (~> 1.4.6)
|
|
98
|
+
rails (~> 3.0.0)
|
|
99
|
+
rcov (~> 0.9.9)
|
|
100
|
+
rspec (~> 2.3.0)
|
|
101
|
+
rspec-rails (~> 2.3.1)
|
|
102
|
+
sqlite3-ruby
|
|
103
|
+
tartarus!
|
|
104
|
+
will_paginate (~> 3.0.pre2)
|
data/README.rdoc
CHANGED
|
@@ -12,23 +12,44 @@ If you wish to use the generator to build the exception viewing/manging interfac
|
|
|
12
12
|
dependencies are used:
|
|
13
13
|
|
|
14
14
|
* will_paginate
|
|
15
|
+
* json
|
|
15
16
|
* jquery
|
|
16
17
|
|
|
17
18
|
=== Installation
|
|
18
19
|
|
|
20
|
+
==== Rails 2.x
|
|
21
|
+
|
|
19
22
|
1. Install the gem from:
|
|
20
|
-
gem install tartarus
|
|
23
|
+
gem install tartarus --version=1.0.3
|
|
24
|
+
|
|
21
25
|
2. Add the tartarus gem dependency to your enviroment.rb:
|
|
22
26
|
config.gem "tartarus"
|
|
27
|
+
|
|
23
28
|
3. Run the generator from the root of your Rails application:
|
|
24
29
|
script/generate tartarus
|
|
25
|
-
|
|
30
|
+
|
|
31
|
+
==== Rails 3.x
|
|
32
|
+
|
|
33
|
+
1. Add the tartarus gem to your Gemfile:
|
|
34
|
+
gem 'tartarus', '2.0.0'
|
|
35
|
+
|
|
36
|
+
2. Run 'bundle install' to install the gem.
|
|
37
|
+
|
|
38
|
+
3. Run the generator from the root of your Rails application:
|
|
39
|
+
rails generate tartarus
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
==== Complete Setup
|
|
43
|
+
1. Run the migration that was generated:
|
|
26
44
|
rake db:migrate
|
|
27
|
-
|
|
45
|
+
|
|
46
|
+
2. Add "config.middleware.use 'Tartarus::Rack' to the enviroments that you'd like logging in.
|
|
47
|
+
|
|
48
|
+
3. Add the javascript and stylesheet includes in your layout:
|
|
28
49
|
<script type="text/javascript" src="/javascripts/tartarus.jquery.js"></script>
|
|
29
50
|
<link href="/stylesheets/tartarus.css" media="all" rel="stylesheet" type="text/css" />
|
|
30
51
|
|
|
31
|
-
|
|
52
|
+
==== Configuration
|
|
32
53
|
|
|
33
54
|
Configuration is handled by config/exceptions.yml, which will be generated for you. You typically
|
|
34
55
|
will not need to change anything in here, however you can use this to set an email address to
|
|
@@ -37,6 +58,11 @@ to send the notification, and is handled per-exception grouping (you will be not
|
|
|
37
58
|
threshold is reached, so with the default of 10 you will be notified at 10,20,30,etc.). In addition,
|
|
38
59
|
when an email is set, a notification will always be sent everytime a new type of exception is raised.
|
|
39
60
|
|
|
61
|
+
==== TODO
|
|
62
|
+
|
|
63
|
+
* Campfire notifications
|
|
64
|
+
* Move configuration from the YAML file into the middleware initializer.
|
|
65
|
+
|
|
40
66
|
=== License
|
|
41
67
|
|
|
42
68
|
Copyright (c) 2009 Daniel Insley
|
data/Rakefile
CHANGED
|
@@ -1,38 +1,20 @@
|
|
|
1
1
|
require 'rubygems'
|
|
2
2
|
require 'rake'
|
|
3
|
+
require 'bundler'
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
require 'jeweler'
|
|
6
|
-
Jeweler::Tasks.new do |gem|
|
|
7
|
-
gem.name = "tartarus"
|
|
8
|
-
gem.summary = %Q{Exception Logging for Rails}
|
|
9
|
-
gem.description = %Q{Provides exception logging and a generator for creating a clean interface to manage exceptions.}
|
|
10
|
-
gem.email = "dinsley@gmail.com"
|
|
11
|
-
gem.homepage = "http://github.com/dinsley/tartarus"
|
|
12
|
-
gem.authors = ["Daniel Insley"]
|
|
13
|
-
gem.add_dependency "will_paginate"
|
|
14
|
-
gem.add_development_dependency "rails"
|
|
15
|
-
gem.add_development_dependency "rspec"
|
|
16
|
-
gem.add_development_dependency "rspec-rails"
|
|
17
|
-
# Gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
|
18
|
-
end
|
|
19
|
-
rescue LoadError
|
|
20
|
-
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
|
21
|
-
end
|
|
5
|
+
Bundler::GemHelper.install_tasks
|
|
22
6
|
|
|
23
|
-
require
|
|
7
|
+
require "rspec/core/rake_task"
|
|
24
8
|
|
|
25
|
-
|
|
26
|
-
spec.
|
|
27
|
-
spec.
|
|
28
|
-
spec.
|
|
29
|
-
spec.
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
end
|
|
9
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
|
10
|
+
spec.rspec_opts = ['--color', '--format progress']
|
|
11
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
|
12
|
+
# spec.rcov = true
|
|
13
|
+
# spec.rcov_opts = lambda do
|
|
14
|
+
# IO.readlines("spec/rcov.opts").map { |l| l.chomp.split " " }.flatten
|
|
15
|
+
# end
|
|
33
16
|
end
|
|
34
17
|
|
|
35
|
-
task :spec => :check_dependencies
|
|
36
18
|
task :default => :spec
|
|
37
19
|
|
|
38
20
|
require 'rake/rdoctask'
|
|
@@ -5,10 +5,11 @@ Usage:
|
|
|
5
5
|
If you do not pass any arguments, the model class will default to "LoggedException".
|
|
6
6
|
|
|
7
7
|
Examples:
|
|
8
|
-
|
|
8
|
+
rails generate tartarus
|
|
9
9
|
|
|
10
10
|
Creates default logged exception model, controller, and views.
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
rails generate tartarus MyException
|
|
13
|
+
|
|
14
|
+
Creates a custom model, controller, and views.
|
|
13
15
|
|
|
14
|
-
Creates a custom model, controller, and views.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
class TartarusGenerator < Rails::Generators::NamedBase
|
|
2
|
+
include Rails::Generators::Migration
|
|
3
|
+
|
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
|
5
|
+
argument :name, :type => 'string', :default => 'LoggedException'
|
|
6
|
+
|
|
7
|
+
def generate_tartarus
|
|
8
|
+
template 'config/exceptions.yml', 'config/exceptions.yml'
|
|
9
|
+
template 'app/models/logged_exception.rb', "app/models/#{file_name}.rb"
|
|
10
|
+
template 'spec/models/logged_exception_spec.rb', "spec/models/#{file_name}_spec.rb"
|
|
11
|
+
|
|
12
|
+
template 'app/controllers/exceptions_controller.rb', "app/controllers/#{plural_name}_controller.rb"
|
|
13
|
+
template 'spec/controllers/exceptions_controller_spec.rb', "spec/controllers/#{plural_name}_controller_spec.rb"
|
|
14
|
+
|
|
15
|
+
copy_file 'app/views/exceptions/index.html.erb', "app/views/#{plural_name}/index.html.erb"
|
|
16
|
+
copy_file 'app/views/exceptions/details.html.erb', "app/views/#{plural_name}/details.html.erb"
|
|
17
|
+
copy_file 'app/views/exceptions/_exception.html.erb', "app/views/#{plural_name}/_exception.html.erb"
|
|
18
|
+
|
|
19
|
+
copy_file 'public/javascripts/tartarus.jquery.js', 'public/javascripts/tartarus.jquery.js'
|
|
20
|
+
copy_file 'public/stylesheets/tartarus.css', 'public/stylesheets/tartarus.css'
|
|
21
|
+
|
|
22
|
+
migration_template "db/migrate/add_logged_exceptions.rb", "db/migrate/add_#{singular_name}_table"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def after_generate
|
|
26
|
+
puts "\nIn order for exceptional to function properly, you'll need to complete the following steps to complete the installation process: \n\n"
|
|
27
|
+
puts " 1) Run 'rake db:migrate' to generate the logging table for your model.\n"
|
|
28
|
+
puts " 2) Add \"config.middleware.use 'Tartarus::Rack'\" to the enviroments that you'd like logging."
|
|
29
|
+
puts " 3) Add '/javascripts/tartarus.jquery.js', and 'stylesheets/tartarus.css' to your applications layout.\n"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def self.next_migration_number(path)
|
|
33
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
end
|
data/{generators → lib/generators}/tartarus/templates/app/controllers/exceptions_controller.rb
RENAMED
|
File without changes
|
|
File without changes
|
data/{generators → lib/generators}/tartarus/templates/app/views/exceptions/_exception.html.erb
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
data/{generators → lib/generators}/tartarus/templates/spec/controllers/exceptions_controller_spec.rb
RENAMED
|
@@ -24,7 +24,7 @@ describe ExceptionsController do
|
|
|
24
24
|
<%= class_name %>.should_receive(:paginate).with(:all, :conditions => { :group_id => '89hasd98ashdasas98dhsda' },
|
|
25
25
|
:order => 'created_at DESC', :page => '1', :per_page => 1).and_return([@exception, @exception2])
|
|
26
26
|
|
|
27
|
-
get :details, :id => '89hasd98ashdasas98dhsda', :page => 1
|
|
27
|
+
get :details, :id => '89hasd98ashdasas98dhsda', :page => '1'
|
|
28
28
|
assigns[:exceptions].should == [@exception, @exception2]
|
|
29
29
|
end
|
|
30
30
|
|
|
File without changes
|
data/lib/tartarus.rb
CHANGED
|
@@ -2,9 +2,11 @@ require 'yaml'
|
|
|
2
2
|
require 'will_paginate'
|
|
3
3
|
|
|
4
4
|
class Tartarus
|
|
5
|
+
module Notifiers; end
|
|
6
|
+
|
|
5
7
|
class << self
|
|
6
8
|
def configuration
|
|
7
|
-
@
|
|
9
|
+
@cached_configuration ||= YAML.load_file("#{Rails.root}/config/exceptions.yml")[Rails.env]
|
|
8
10
|
end
|
|
9
11
|
|
|
10
12
|
def logger_class
|
|
@@ -21,6 +23,8 @@ class Tartarus
|
|
|
21
23
|
end
|
|
22
24
|
end
|
|
23
25
|
|
|
26
|
+
require 'tartarus/rack'
|
|
24
27
|
require 'tartarus/logger'
|
|
25
|
-
require 'tartarus/
|
|
26
|
-
require 'tartarus/
|
|
28
|
+
require 'tartarus/notifiers/mail'
|
|
29
|
+
require 'tartarus/railtie'
|
|
30
|
+
|
data/lib/tartarus/logger.rb
CHANGED
|
@@ -1,35 +1,71 @@
|
|
|
1
1
|
module Tartarus::Logger
|
|
2
|
-
def group_count
|
|
3
|
-
self.class.count( :conditions => ["group_id = ?", group_id] )
|
|
4
|
-
end
|
|
5
|
-
|
|
6
|
-
def handle_notifications
|
|
7
|
-
notification_address = Tartarus.configuration['notification_address']
|
|
8
|
-
return unless notification_address.present?
|
|
9
|
-
Tartarus::Notifier.deliver_notification( notification_address, self ) if group_count == 1 or (group_count%Tartarus.configuration['notification_threshold']).zero?
|
|
10
|
-
end
|
|
11
|
-
|
|
12
2
|
def self.included(base)
|
|
13
3
|
base.extend ClassMethods
|
|
14
|
-
base.
|
|
4
|
+
base.send :include, InstanceMethods
|
|
5
|
+
base.send :before_save, :json_serialize
|
|
6
|
+
base.send :after_save, :json_deserialize
|
|
7
|
+
base.send :after_find, :json_deserialize
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
module InstanceMethods
|
|
11
|
+
def group_count
|
|
12
|
+
self.class.count( :conditions => ["group_id = ?", group_id] )
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def handle_notifications
|
|
16
|
+
notification_address = Tartarus.configuration['notification_address']
|
|
17
|
+
return unless notification_address.present?
|
|
18
|
+
Tartarus::Notifiers::Mail.deliver_notification( notification_address, self ) if group_count == 1 or (group_count%Tartarus.configuration['notification_threshold']).zero?
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def json_serialize
|
|
22
|
+
self.request = self.request.to_json
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def json_deserialize
|
|
26
|
+
self.request = JSON.parse(request)
|
|
27
|
+
end
|
|
28
|
+
|
|
15
29
|
end
|
|
16
30
|
|
|
17
31
|
module ClassMethods
|
|
18
|
-
def log(
|
|
32
|
+
def log(env, exception)
|
|
19
33
|
logged = create do |logged_exception|
|
|
34
|
+
controller = env['action_controller.instance']
|
|
20
35
|
group_id = "#{exception.class.name}#{exception.message.gsub(/(#<.+):(.+)(>)/,'\1\3')}#{controller.controller_path}#{controller.action_name}"
|
|
21
|
-
|
|
36
|
+
|
|
22
37
|
logged_exception.exception_class = exception.class.name
|
|
23
38
|
logged_exception.controller_path = controller.controller_path
|
|
24
39
|
logged_exception.action_name = controller.action_name
|
|
25
40
|
logged_exception.message = exception.message
|
|
26
41
|
logged_exception.backtrace = exception.backtrace * "\n"
|
|
27
|
-
logged_exception.request =
|
|
42
|
+
logged_exception.request = self.normalize_request_data(env)
|
|
28
43
|
logged_exception.group_id = Digest::SHA1.hexdigest(group_id)
|
|
29
44
|
end
|
|
30
45
|
logged.handle_notifications
|
|
31
46
|
logged
|
|
32
47
|
end
|
|
33
48
|
|
|
49
|
+
def normalize_request_data(env)
|
|
50
|
+
request = env['action_controller.instance'].request
|
|
51
|
+
|
|
52
|
+
request_details = {
|
|
53
|
+
:enviroment => { :process => $$, :server => `hostname -s`.chomp },
|
|
54
|
+
:session => { :variables => request.env['rack.session'].to_hash, :cookie => request.env['rack.request.cookie_hash'] },
|
|
55
|
+
:http_details => {
|
|
56
|
+
:method => request.method.to_s.upcase,
|
|
57
|
+
:url => "#{request.protocol}#{request.env["HTTP_HOST"]}#{request.fullpath}",
|
|
58
|
+
:format => request.format.to_s,
|
|
59
|
+
:parameters => request.filtered_parameters
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
request.env.each_pair do |key, value|
|
|
64
|
+
request_details[:enviroment][key.downcase] = value if key.match(/^[A-Z_]*$/)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
return request_details
|
|
68
|
+
end
|
|
69
|
+
|
|
34
70
|
end
|
|
35
71
|
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
class Tartarus::Notifiers::Mail < ActionMailer::Base
|
|
2
|
+
|
|
3
|
+
def notification(address, exception)
|
|
4
|
+
subject = "Exception raised at #{exception.controller_path}##{exception.action_name} (#{exception.exception_class}) #{exception.message}"
|
|
5
|
+
mail(:to => address, :from => Tartarus.configuration['sender'], :subject => subject) do |format|
|
|
6
|
+
format.text do
|
|
7
|
+
render :text => %{
|
|
8
|
+
A new exception was raised (#{exception.created_at.strftime("%m/%d/%Y %I:%M%p")}):
|
|
9
|
+
|
|
10
|
+
Class : #{exception.exception_class}
|
|
11
|
+
Location : #{exception.controller_path}##{exception.action_name}
|
|
12
|
+
Message : #{exception.message}
|
|
13
|
+
Count : #{exception.group_count}
|
|
14
|
+
|
|
15
|
+
Backtrace:
|
|
16
|
+
#{exception.backtrace}
|
|
17
|
+
|
|
18
|
+
Request:
|
|
19
|
+
#{exception.request}
|
|
20
|
+
}
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|