rusen 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 85f19290071430461d1bee9c0253d1d7031a60d7
4
+ data.tar.gz: 0b485c11d07d898a8c897db28e515964c23c3bec
5
+ SHA512:
6
+ metadata.gz: 32cd6604c8f416c84734eb675e4efed7d8fbe9755f1011ce896020f06fc6530ada42374ccb7a1fbc6e190a151160c882b152a5e5002dc64c5029d1a10f9d3bdd
7
+ data.tar.gz: 1134462504991f8f3ab70b9fd7ee7ee325521b699ad62cba46b35801cee5b1489eef4ed1f344648ead86ded2d096b4b73509fd3358defba71ed2207ce1ca5f90
data/CHANGELOG.md ADDED
@@ -0,0 +1,23 @@
1
+ ## HEAD
2
+ - Moved presentation to templates by Adrian Gomez
3
+ - Improve specs by Adrian Gomez
4
+ - Fix default params by Adrian Gomez
5
+ - Add log4r support by Adrian Gomez
6
+ - Fix gemspec by Peter Boling
7
+ - Add LICENSE (MIT) by Peter Boling
8
+ - Make VERSION accessible from Ruby (compatible with gem-release) by Peter Boling
9
+ - Added Trvis-CI and Coveralls integration by Peter Boling
10
+ - Added Rakefile by Peter Boling
11
+ - Test against RUby 1.8.7, 1.9.2, 1.9.3, 2.0.0, and jRuby19 by Peter Boling
12
+ - Added MailNotifier (for Mail gem) by Peter Boling
13
+ - Made mail and pony gems not explicit dependencies; notifiers are loaded dynamically by Peter Boling
14
+ - Settings.outputs needs to default to [] in order for the gem to have no default dependencies by Peter Boling
15
+
16
+ ## 0.0.2 (2013-01-28)
17
+ - Fix when a notificator can't notify by Adrian Gomez
18
+ - Added documentation by Adrian Gomez
19
+ - Added possibility to skip notification of certain errors by Adrian Gomez
20
+
21
+ ## 0.0.1 (2013-01-28)
22
+
23
+ First release by Adrian Gomez
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Adrian Gomez
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,262 @@
1
+ [RU]by [S]imple [E]xception [N]otification
2
+ ====
3
+
4
+ The Ruby Simple Exception Notification (a.k.a Rusen) gem provides a simple way for logging and sending errors in any ruby application.
5
+
6
+ The notification includes information about the current request, session, environment and also gives a backtrace of the exception.
7
+
8
+ | Project | Rusen |
9
+ |------------------------ | ----------------- |
10
+ | gem name | rusen |
11
+ | license | MIT |
12
+ | moldiness | [![Maintainer Status](http://stillmaintained.com/Moove-it/rusen.png)](http://stillmaintained.com/Moove-it/rusen) |
13
+ | version | [![Gem Version](https://badge.fury.io/rb/rusen.png)](http://badge.fury.io/rb/rusen) |
14
+ | dependencies | [![Dependency Status](https://gemnasium.com/Moove-it/rusen.png)](https://gemnasium.com/Moove-it/rusen) |
15
+ | code quality | [![Code Climate](https://codeclimate.com/github/Moove-it/rusen.png)](https://codeclimate.com/github/Moove-it/rusen) |
16
+ | continuous integration | [![Build Status](https://secure.travis-ci.org/Moove-it/rusen.png?branch=master)](https://travis-ci.org/Moove-it/rusen) |
17
+ | test coverage | [![Coverage Status](https://coveralls.io/repos/Moove-it/rusen/badge.png)](https://coveralls.io/r/Moove-it/rusen) |
18
+ | homepage | [https://github.com/Moove-it/rusen][homepage] |
19
+ | documentation | [http://rdoc.info/github/Moove-it/rusen/frames][documentation] |
20
+ | author | [Adrian Gomez](https://coderbits.com/Moove-it) |
21
+
22
+ Installation
23
+ ---
24
+
25
+ Just add the following line in your Gemfile
26
+
27
+ ```ruby
28
+ gem 'rusen'
29
+ ```
30
+
31
+ Usage
32
+ ---
33
+
34
+ ### With global configuration
35
+
36
+ The easiest way to use it is with global configuration.
37
+
38
+ First you configure Rusen
39
+ ```ruby
40
+ require 'rusen'
41
+
42
+ Rusen.settings.outputs = [:io, :email]
43
+ Rusen.settings.sections = [:backtrace, :request, :session, :environment]
44
+ Rusen.settings.email_prefix = '[ERROR] '
45
+ Rusen.settings.sender_address = 'some_email@example.com'
46
+ Rusen.settings.exception_recipients = %w(dev_team@example.com test_team@example.com)
47
+ Rusen.settings.smtp_settings = {
48
+ :address => 'smtp.gmail.com',
49
+ :port => 587,
50
+ :domain => 'example.org',
51
+ :authentication => :plain,
52
+ :user_name => 'dev_team@moove-it.com',
53
+ :password => 'xxxxxxx',
54
+ :enable_starttls_auto => true
55
+ }
56
+ ```
57
+ And the you can start sending notifications:
58
+ ```ruby
59
+ begin
60
+ method.call
61
+ rescue Exception => exception
62
+ Rusen.notify(exception)
63
+ end
64
+ ```
65
+ This way, if you modify the notifications settings at runtime, every notification sent afterwards will use the new settings.
66
+
67
+ ### With local configuration
68
+
69
+ This method lets you have more control when notifying. You may want for example to send an email when a particular exception occurs and just print to stdout otherwise.
70
+ To achieve this you can do the following:
71
+ ```ruby
72
+ @email_settings = Settings.new
73
+ @email_settings.outputs = settings[:email]
74
+ Rusen.settings.sections = [:backtrace, :request, :session]
75
+ @email_settings.email_prefix = '[ERROR] '
76
+ @email_settings.sender_address = 'some_email@example.com'
77
+ @email_settings.exception_recipients = %w(dev_team@example.com test_team@example.com)
78
+ @email_settings.smtp_settings = {
79
+ :address => 'smtp.gmail.com',
80
+ :port => 587,
81
+ :domain => 'example.org',
82
+ :authentication => :plain,
83
+ :user_name => 'dev_team@moove-it.com',
84
+ :password => 'xxxxxxx',
85
+ :enable_starttls_auto => true
86
+ }
87
+
88
+ @email_notifier = Notifier.new(@email_settings)
89
+
90
+ @stdout_settings = Settings.new
91
+ @stdout_settings.outputs = settings[:io]
92
+ Rusen.settings.sections = [:backtrace]
93
+
94
+ @stdout_notifier = Notifier.new(@stdout_settings)
95
+ ```
96
+ and then:
97
+ ```ruby
98
+ begin
99
+ method.call
100
+ rescue SmallException => exception
101
+ @stdout_notifier.notify(exception)
102
+ rescue BigException => exception
103
+ @email_notifier.notify(exception)
104
+ end
105
+ ```
106
+
107
+ Middleware
108
+ ---
109
+ Rusen comes with a rack and rails special (soon to come) middleware for easy usage.
110
+
111
+ ### Rack
112
+ To use Rusen in any rack application you just have to add the following code somewhere in your app (ex: config/initializers/rusen.rb):
113
+ ```ruby
114
+ require 'rusen/middleware/rusen_rack'
115
+
116
+ use Rusen::Middleware::RusenRack,
117
+ :outputs => [:io, :email],
118
+ :sections => [:backtrace, :request, :session, :environment],
119
+ :email_prefix => '[ERROR] ',
120
+ :sender_address => 'some_email@example.com',
121
+ :exception_recipients => %w(dev_team@example.com test_team@example.com),
122
+ :smtp_settings => {
123
+ :address => 'smtp.gmail.com',
124
+ :port => 587,
125
+ :domain => 'example.org',
126
+ :authentication => :plain,
127
+ :user_name => 'dev_team@moove-it.com',
128
+ :password => 'xxxxxxx',
129
+ :enable_starttls_auto => true
130
+ }
131
+ ```
132
+ This will capture any unhandled exception, send an email and write a trace in stdout.
133
+
134
+ Settings
135
+ ---
136
+ ### Outputs
137
+ Currently supported outputs are :io, :lo4r, :pony and :mail. More outputs are easy to add so you can customize Rusen to your needs.
138
+
139
+ Note: :io will only print to stdout for the time being, but there are plans to extend it to anything that Ruby::IO supports.
140
+
141
+ Pony, lo4r and Mail outputs require additional gems to work.
142
+
143
+ To use pony add this to your Gemfile:
144
+ ```ruby
145
+ gem 'pony'
146
+ ```
147
+
148
+ To use mail add this to your Gemfile:
149
+ ```ruby
150
+ gem 'mail'
151
+ ```
152
+
153
+ To use log4r add this to your Gemfile:
154
+ ```ruby
155
+ gem 'log4r'
156
+ ```
157
+
158
+ ### Sections
159
+ You can choose the output sections simply by setting the appropriate values in the configuration.
160
+
161
+ ### Exclude if
162
+ Here you can pass a block that will receive the error. If the block returns false, then the error will be notified.
163
+
164
+ ### Email settings
165
+ All the email settings are self explanatory, but you can contact me if any of them needs clarification.
166
+
167
+ ### Log4r settings
168
+ * logger_name _(required)_: Logger used for logging errors.
169
+ * log4r_config_file _(optional)_: YAML file that contains Log4r configuration. Rusen will load that file when given.
170
+
171
+ Sample of Log4r configuration file contents:
172
+
173
+ ```
174
+ log4r_config:
175
+ loggers:
176
+ - name: error_notifications
177
+ level: ERROR
178
+ trace: false
179
+ outputters:
180
+ - logfile
181
+ - stdoout
182
+
183
+ outputters:
184
+ - type: FileOutputter
185
+ name: logfile
186
+ filename: 'log/service.log'
187
+
188
+ - type: StdoutOutputter
189
+ name: stdout
190
+ ```
191
+
192
+ Sidekiq
193
+ ---
194
+ Rusen comes with sidekiq integration builtin to use just add this to your sidekiq initializer:
195
+ ```ruby
196
+ require 'rusen/sidekiq'
197
+ ```
198
+ You can configure it with the global rusen configuration, ex:
199
+ ```ruby
200
+ require 'rusen/sidekiq'
201
+
202
+ Rusen.settings.sender_address = 'some_email@example.com'
203
+ Rusen.settings.exception_recipients = %w(dev_team@example.com test_team@example.com)
204
+ Rusen.settings.smtp_settings = {
205
+ :address => 'smtp.gmail.com',
206
+ :port => 587,
207
+ :domain => 'example.org',
208
+ :authentication => :plain,
209
+ :user_name => 'dev_team@moove-it.com',
210
+ :password => 'xxxxxxx',
211
+ :enable_starttls_auto => true
212
+ }
213
+ ```
214
+
215
+ Rusen supports versions ~> 2 and ~> 3 of sidekiq.
216
+
217
+ Extending to more outputs
218
+ ---
219
+ Soon to come!
220
+
221
+ ## Authors
222
+
223
+ Adrian Gomez is the author of the code, and current maintainer.
224
+
225
+ ## Contributors
226
+
227
+ See the [Network View](https://github.com/Moove-it/rusen/network) and the [CHANGELOG](https://github.com/Moove-it/rusen/blob/master/CHANGELOG.md)
228
+
229
+ ## Contributing
230
+
231
+ 1. Fork it
232
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
233
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
234
+ 4. Push to the branch (`git push origin my-new-feature`)
235
+ 5. Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
236
+ 6. Create new Pull Request
237
+
238
+ ## Versioning
239
+
240
+ This library aims to adhere to [Semantic Versioning 2.0.0][semver].
241
+ Violations of this scheme should be reported as bugs. Specifically,
242
+ if a minor or patch version is released that breaks backward
243
+ compatibility, a new version should be immediately released that
244
+ restores compatibility. Breaking changes to the public API will
245
+ only be introduced with new major versions.
246
+
247
+ As a result of this policy, you can (and should) specify a
248
+ dependency on this gem using the [Pessimistic Version Constraint][pvc] with two digits of precision.
249
+
250
+ For example:
251
+
252
+ spec.add_dependency 'rusen', '~> 0.0.2'
253
+
254
+ ## Legal
255
+
256
+ * MIT License - See LICENSE file in this project
257
+ * Copyright (c) 2013 Adrian Gomez
258
+
259
+ [semver]: http://semver.org/
260
+ [pvc]: http://docs.rubygems.org/read/chapter/16#page74
261
+ [documentation]: http://rdoc.info/github/Moove-it/rusen/frames
262
+ [homepage]: https://github.com/Moove-it/rusen
data/Rakefile ADDED
@@ -0,0 +1,65 @@
1
+ # encoding: utf-8
2
+ #!/usr/bin/env rake
3
+ require "bundler/gem_tasks"
4
+ require 'rake'
5
+
6
+ require 'rspec/core'
7
+ require 'rspec/core/rake_task'
8
+ RSpec::Core::RakeTask.new(:spec) do |spec|
9
+ spec.pattern = FileList['spec/**/*_spec.rb']
10
+ end
11
+
12
+ require 'reek/rake/task'
13
+ Reek::Rake::Task.new do |t|
14
+ t.fail_on_error = true
15
+ t.verbose = false
16
+ t.source_files = 'lib/**/*.rb'
17
+ end
18
+
19
+ require 'roodi'
20
+ require 'roodi_task'
21
+ RoodiTask.new do |t|
22
+ t.verbose = false
23
+ end
24
+
25
+ task :default => :spec
26
+
27
+ namespace :test do
28
+ desc 'Test against all supported Rails versions'
29
+ task :all do
30
+ if RUBY_VERSION == '1.8.7'
31
+ %w( 2.2.x 2.3.x 3.1.x 3.2.x ).each do |rails_version|
32
+ sh "BUNDLE_GEMFILE='gemfiles/Gemfile.rails-#{rails_version}' bundle --quiet"
33
+ sh "BUNDLE_GEMFILE='gemfiles/Gemfile.rails-#{rails_version}' bundle exec rspec spec"
34
+ end
35
+ elsif RUBY_VERSION == '1.9.2'
36
+ %w( 2.3.x 3.1.x 3.2.x ).each do |rails_version|
37
+ sh "BUNDLE_GEMFILE='gemfiles/Gemfile.rails-#{rails_version}' bundle --quiet"
38
+ sh "BUNDLE_GEMFILE='gemfiles/Gemfile.rails-#{rails_version}' bundle exec rspec spec"
39
+ end
40
+ elsif RUBY_VERSION == '1.9.3'
41
+ %w( 3.1.x 3.2.x 4.0.x ).each do |rails_version|
42
+ sh "BUNDLE_GEMFILE='gemfiles/Gemfile.rails-#{rails_version}' bundle --quiet"
43
+ sh "BUNDLE_GEMFILE='gemfiles/Gemfile.rails-#{rails_version}' bundle exec rspec spec"
44
+ end
45
+ elsif RUBY_VERSION == '2.0.0'
46
+ %w( 3.1.x 3.2.x 4.0.x ).each do |rails_version|
47
+ sh "BUNDLE_GEMFILE='gemfiles/Gemfile.rails-#{rails_version}' bundle --quiet"
48
+ sh "BUNDLE_GEMFILE='gemfiles/Gemfile.rails-#{rails_version}' bundle exec rspec spec"
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ #require File.expand_path('../lib/rusen/version', __FILE__)
55
+ #require 'rdoc'
56
+ #require 'rdoc/task'
57
+ #RDoc::Task.new do |rdoc|
58
+ # rdoc.rdoc_dir = 'rdoc'
59
+ # rdoc.title = "Rusen #{Rusen::VERSION}"
60
+ # rdoc.options << '--line-numbers'
61
+ # rdoc.rdoc_files.include('README*')
62
+ # rdoc.rdoc_files.include('lib/**/*.rb')
63
+ #end
64
+
65
+ Bundler::GemHelper.install_tasks
data/lib/rusen.rb CHANGED
@@ -1,10 +1,10 @@
1
+ require 'rusen/version'
1
2
  require 'rusen/settings'
2
3
  require 'rusen/notifier'
3
4
 
4
5
  module Rusen
5
6
 
6
7
  @settings = Settings.new
7
- @notifier = Notifier.new(@settings)
8
8
 
9
9
  # Returns the global settings for rusen.
10
10
  #
@@ -17,7 +17,11 @@ module Rusen
17
17
 
18
18
  # (see Rusen::Notifier#notify)
19
19
  def self.notify(exception, request = nil, environment = nil, session = nil)
20
- @notifier.notify(exception, request, environment, session)
20
+ notifier.notify(exception, request, environment, session)
21
+ end
22
+
23
+ def self.notifier
24
+ @notifier || Notifier.new(@settings)
21
25
  end
22
26
 
23
27
  end
@@ -10,15 +10,19 @@ module Rusen
10
10
  def initialize(app, settings = {})
11
11
  @app = app
12
12
 
13
- @rusen_settings = Settings.new
14
-
15
- @rusen_settings.outputs = settings[:outputs]
16
- @rusen_settings.sections = settings[:sections]
17
- @rusen_settings.email_prefix = settings[:email_prefix]
18
- @rusen_settings.sender_address = settings[:sender_address]
19
- @rusen_settings.exception_recipients = settings[:exception_recipients]
20
- @rusen_settings.smtp_settings = settings[:smtp_settings]
21
- @rusen_settings.exclude_if = settings[:exclude_if]
13
+ if settings.is_a?(::Rusen::Settings)
14
+ @rusen_settings = settings
15
+ else
16
+ @rusen_settings = Settings.new
17
+
18
+ @rusen_settings.outputs = settings[:outputs]
19
+ @rusen_settings.sections = settings[:sections]
20
+ @rusen_settings.email_prefix = settings[:email_prefix]
21
+ @rusen_settings.sender_address = settings[:sender_address]
22
+ @rusen_settings.exception_recipients = settings[:exception_recipients]
23
+ @rusen_settings.smtp_settings = settings[:smtp_settings]
24
+ @rusen_settings.exclude_if = settings[:exclude_if]
25
+ end
22
26
 
23
27
  @notifier = Notifier.new(@rusen_settings)
24
28
  end
@@ -0,0 +1,19 @@
1
+ require 'rusen'
2
+ require 'sidekiq'
3
+
4
+ module Rusen
5
+ module Middleware
6
+ class RusenSidekiq
7
+ include Sidekiq::Util
8
+
9
+ def call(worker, msg, queue, &block)
10
+ yield
11
+ rescue => error
12
+ Rusen.notify(error)
13
+
14
+ raise
15
+ end
16
+
17
+ end
18
+ end
19
+ end