failsafe 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +7 -1
- data/lib/failsafe/backends/exceptional.rb +11 -0
- data/lib/failsafe/backends/file.rb +14 -1
- data/lib/failsafe/failure.rb +5 -3
- data/lib/failsafe/version.rb +1 -1
- data/spec/failsafe/backends/airbrake_spec.rb +19 -0
- data/spec/failsafe/backends/exceptional_spec.rb +19 -0
- data/spec/failsafe/backends/file_spec.rb +56 -0
- metadata +9 -2
data/README.md
CHANGED
@@ -58,7 +58,13 @@ by failsafe, the exception object is handed to each error backend.
|
|
58
58
|
Failsafe ships with three error backends by default:
|
59
59
|
|
60
60
|
* Airbrake - Send errors to airbrake
|
61
|
+
* Exceptional - Send errors to exceptional
|
61
62
|
* Stderr - Send errors to stderr
|
62
63
|
* File - Send errors to a log file
|
63
64
|
|
64
|
-
Note: The File backend logs to a log file in the log directory called
|
65
|
+
Note: The File backend by default logs to a log file in the log directory called
|
66
|
+
failsafe_errors.log. It can be optionally configured with a different path:
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
Failsafe::Backends::File.log_file_path = "/path/to/errors.log"
|
70
|
+
```
|
@@ -3,8 +3,21 @@ module Failsafe
|
|
3
3
|
|
4
4
|
# File failure backend. Writes exception backtraces to a logfile.
|
5
5
|
class File < Base
|
6
|
+
def self.log_file_path=(log_file_path)
|
7
|
+
@logger = nil
|
8
|
+
@log_file_path = log_file_path
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.log_file_path
|
12
|
+
@log_file_path || ::File.join(Rails.root, 'log', 'failsafe_errors.log')
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.configure
|
16
|
+
yield(self)
|
17
|
+
end
|
18
|
+
|
6
19
|
def self.logger
|
7
|
-
@logger ||= ::Logger.new(
|
20
|
+
@logger ||= ::Logger.new(log_file_path).tap { |l| l.formatter = Logger::Formatter.new }
|
8
21
|
end
|
9
22
|
|
10
23
|
def save
|
data/lib/failsafe/failure.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
module Failsafe
|
2
2
|
module Backends
|
3
|
-
autoload :Base,
|
3
|
+
autoload :Base, 'failsafe/backends/base'
|
4
4
|
|
5
|
-
autoload :Airbrake,
|
6
|
-
autoload :
|
5
|
+
autoload :Airbrake, 'failsafe/backends/airbrake'
|
6
|
+
autoload :File, 'failsafe/backends/file'
|
7
|
+
autoload :Stderr, 'failsafe/backends/stderr'
|
8
|
+
autoload :Exceptional, 'failsafe/backends/exceptional'
|
7
9
|
end
|
8
10
|
end
|
data/lib/failsafe/version.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
begin
|
4
|
+
Airbrake
|
5
|
+
rescue NameError
|
6
|
+
module Airbrake; end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe Failsafe::Backends::Airbrake do
|
10
|
+
let(:exception) { stub("exception") }
|
11
|
+
|
12
|
+
subject { Failsafe::Backends::Airbrake.new(exception) }
|
13
|
+
|
14
|
+
it "tells airbrake to notify or ignore the exception" do
|
15
|
+
::Airbrake.expects(:notify_or_ignore).with(exception)
|
16
|
+
subject.save
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
begin
|
4
|
+
Exceptional
|
5
|
+
rescue NameError
|
6
|
+
module Exceptional;end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe Failsafe::Backends::Exceptional do
|
10
|
+
let(:exception) { stub("exception") }
|
11
|
+
|
12
|
+
subject { Failsafe::Backends::Exceptional.new(exception) }
|
13
|
+
|
14
|
+
it "tells airbrake to notify or ignore the exception" do
|
15
|
+
::Exceptional.expects(:handle).with(exception)
|
16
|
+
subject.save
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'tempfile'
|
3
|
+
|
4
|
+
begin
|
5
|
+
Rails
|
6
|
+
rescue NameError
|
7
|
+
module Rails; end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe Failsafe::Backends::File, "configuration" do
|
11
|
+
let(:log_file_path) { Tempfile.new("failsafe").path }
|
12
|
+
let(:tmpdir) { Dir.mktmpdir("failsafe") }
|
13
|
+
|
14
|
+
it "allows for setting the log file path" do
|
15
|
+
Failsafe::Backends::File.configure do |c|
|
16
|
+
c.log_file_path = log_file_path
|
17
|
+
end
|
18
|
+
|
19
|
+
Failsafe::Backends::File.log_file_path.should == log_file_path
|
20
|
+
end
|
21
|
+
|
22
|
+
it "defaults the log file to the [Rails.root]/log/failsafe_errors.log" do
|
23
|
+
Failsafe::Backends::File.configure do |c|
|
24
|
+
c.log_file_path = nil
|
25
|
+
end
|
26
|
+
|
27
|
+
Rails.stubs(:root).returns(tmpdir)
|
28
|
+
Failsafe::Backends::File.log_file_path.should == ::File.join(tmpdir, "log", "failsafe_errors.log")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe Failsafe::Backends::File do
|
33
|
+
let(:exception) { RuntimeError.new("Oh noez!") }
|
34
|
+
let(:log_file) { Tempfile.new("failsafe") }
|
35
|
+
|
36
|
+
subject { Failsafe::Backends::File.new(exception) }
|
37
|
+
|
38
|
+
before do
|
39
|
+
Failsafe::Backends::File.log_file_path = log_file.path
|
40
|
+
exception.set_backtrace(["#{__FILE__}:6"])
|
41
|
+
subject.save
|
42
|
+
end
|
43
|
+
|
44
|
+
after do
|
45
|
+
log_file.close!
|
46
|
+
end
|
47
|
+
|
48
|
+
it "logs to the logfile when a exception is raised" do
|
49
|
+
log_file.read.should =~ /Oh noez!/
|
50
|
+
end
|
51
|
+
|
52
|
+
it "logs the backtrace to the file" do
|
53
|
+
log_file.read.should =~ /file_spec.rb:6/
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: failsafe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-06-26 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: ''
|
15
15
|
email:
|
@@ -29,11 +29,15 @@ files:
|
|
29
29
|
- lib/failsafe.rb
|
30
30
|
- lib/failsafe/backends/airbrake.rb
|
31
31
|
- lib/failsafe/backends/base.rb
|
32
|
+
- lib/failsafe/backends/exceptional.rb
|
32
33
|
- lib/failsafe/backends/file.rb
|
33
34
|
- lib/failsafe/backends/stderr.rb
|
34
35
|
- lib/failsafe/failure.rb
|
35
36
|
- lib/failsafe/version.rb
|
37
|
+
- spec/failsafe/backends/airbrake_spec.rb
|
36
38
|
- spec/failsafe/backends/base_spec.rb
|
39
|
+
- spec/failsafe/backends/exceptional_spec.rb
|
40
|
+
- spec/failsafe/backends/file_spec.rb
|
37
41
|
- spec/failsafe/backends/stderr_spec.rb
|
38
42
|
- spec/failsafe_spec.rb
|
39
43
|
- spec/spec_helper.rb
|
@@ -63,7 +67,10 @@ specification_version: 3
|
|
63
67
|
summary: Tiny little library for silently handling errors so they don't interrupt
|
64
68
|
program flow.
|
65
69
|
test_files:
|
70
|
+
- spec/failsafe/backends/airbrake_spec.rb
|
66
71
|
- spec/failsafe/backends/base_spec.rb
|
72
|
+
- spec/failsafe/backends/exceptional_spec.rb
|
73
|
+
- spec/failsafe/backends/file_spec.rb
|
67
74
|
- spec/failsafe/backends/stderr_spec.rb
|
68
75
|
- spec/failsafe_spec.rb
|
69
76
|
- spec/spec_helper.rb
|