safely 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +9 -1
- data/README.rdoc +1 -1
- data/lib/safely.rb +5 -4
- data/lib/safely/backtrace.rb +48 -0
- data/safely.gemspec +8 -1
- data/spec/backtrace/safe.rb +12 -0
- data/spec/backtrace/unsafe.rb +8 -0
- data/spec/backtrace_spec.rb +33 -0
- metadata +9 -2
data/CHANGES
CHANGED
data/README.rdoc
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Safely is a simple exception handling and alerting mechanism extract from the daemon-kit[https://github.com/kennethkalmer/daemon-kit] project.
|
4
4
|
|
5
|
-
Safely currently supports error reporting to Hoptoad, or via email.
|
5
|
+
Safely currently supports error reporting to Hoptoad, or via email. Safely can also log all exceptions to a file when a program exited abnormally, shedding light on what caused the failures.
|
6
6
|
|
7
7
|
== Installation and Usage
|
8
8
|
|
data/lib/safely.rb
CHANGED
@@ -2,11 +2,12 @@ $:.unshift File.expand_path('../', __FILE__)
|
|
2
2
|
|
3
3
|
module Safely
|
4
4
|
|
5
|
-
VERSION = "0.
|
5
|
+
VERSION = "0.3.0"
|
6
6
|
|
7
|
-
autoload :
|
8
|
-
autoload :
|
9
|
-
autoload :
|
7
|
+
autoload :Backtrace, 'safely/backtrace'
|
8
|
+
autoload :Config, 'safely/config'
|
9
|
+
autoload :Mixin, 'safely/mixin'
|
10
|
+
autoload :Strategy, 'safely/strategy'
|
10
11
|
|
11
12
|
class << self
|
12
13
|
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Safely
|
2
|
+
class Backtrace
|
3
|
+
|
4
|
+
class << self
|
5
|
+
|
6
|
+
attr_accessor :trace_directory
|
7
|
+
|
8
|
+
def enable!
|
9
|
+
@enabled = true
|
10
|
+
at_exit { log_exceptions }
|
11
|
+
end
|
12
|
+
|
13
|
+
def safe_shutdown!
|
14
|
+
@enabled = false
|
15
|
+
end
|
16
|
+
|
17
|
+
def log_exceptions
|
18
|
+
return unless @enabled && self.trace_directory && File.directory?( self.trace_directory )
|
19
|
+
|
20
|
+
require 'logger'
|
21
|
+
|
22
|
+
trace_file = File.join( self.trace_directory, "backtrace-#{Time.now.strftime('%Y%m%d%H%M%S')}-#{Process.pid}.log" )
|
23
|
+
trace_log = Logger.new( trace_file )
|
24
|
+
|
25
|
+
# Find the last exception
|
26
|
+
e = nil
|
27
|
+
ObjectSpace.each_object {|o|
|
28
|
+
if ::Exception === o
|
29
|
+
e = o
|
30
|
+
end
|
31
|
+
}
|
32
|
+
|
33
|
+
trace_log.info "*** Below you'll find the most recent exception thrown, this will likely (but not certainly) be the exception that made #{DaemonKit.configuration.daemon_name} exit abnormally ***"
|
34
|
+
trace_log.error e
|
35
|
+
|
36
|
+
trace_log.info "*** Below you'll find all the exception objects in memory, some of them may have been thrown in your application, others may just be in memory because they are standard exceptions ***"
|
37
|
+
ObjectSpace.each_object {|o|
|
38
|
+
if ::Exception === o
|
39
|
+
trace_log.error o
|
40
|
+
end
|
41
|
+
}
|
42
|
+
|
43
|
+
trace_log.close
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
data/safely.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{safely}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kenneth Kalmer"]
|
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
|
|
27
27
|
"Rakefile",
|
28
28
|
"VERSION",
|
29
29
|
"lib/safely.rb",
|
30
|
+
"lib/safely/backtrace.rb",
|
30
31
|
"lib/safely/config.rb",
|
31
32
|
"lib/safely/mixin.rb",
|
32
33
|
"lib/safely/strategy.rb",
|
@@ -34,6 +35,9 @@ Gem::Specification.new do |s|
|
|
34
35
|
"lib/safely/strategy/log.rb",
|
35
36
|
"lib/safely/strategy/mail.rb",
|
36
37
|
"safely.gemspec",
|
38
|
+
"spec/backtrace/safe.rb",
|
39
|
+
"spec/backtrace/unsafe.rb",
|
40
|
+
"spec/backtrace_spec.rb",
|
37
41
|
"spec/config_spec.rb",
|
38
42
|
"spec/safely_spec.rb",
|
39
43
|
"spec/spec_helper.rb",
|
@@ -48,6 +52,9 @@ Gem::Specification.new do |s|
|
|
48
52
|
s.rubygems_version = %q{1.7.2}
|
49
53
|
s.summary = %q{Safely run your code, keep track of exceptions}
|
50
54
|
s.test_files = [
|
55
|
+
"spec/backtrace/safe.rb",
|
56
|
+
"spec/backtrace/unsafe.rb",
|
57
|
+
"spec/backtrace_spec.rb",
|
51
58
|
"spec/config_spec.rb",
|
52
59
|
"spec/safely_spec.rb",
|
53
60
|
"spec/spec_helper.rb",
|
@@ -0,0 +1,12 @@
|
|
1
|
+
$:.unshift File.expand_path('../../../lib', __FILE__)
|
2
|
+
|
3
|
+
require 'safely'
|
4
|
+
|
5
|
+
Safely::Backtrace.trace_directory = File.expand_path('../tmp', __FILE__)
|
6
|
+
Safely::Backtrace.enable!
|
7
|
+
|
8
|
+
safely do
|
9
|
+
raise "Oops :/"
|
10
|
+
end
|
11
|
+
|
12
|
+
Safely::Backtrace.safe_shutdown!
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
describe Safely::Backtrace do
|
5
|
+
before(:each) do
|
6
|
+
@temp_dir = File.expand_path('../backtrace/tmp', __FILE__)
|
7
|
+
|
8
|
+
FileUtils.rm_rf( @temp_dir )
|
9
|
+
FileUtils.mkdir_p( @temp_dir )
|
10
|
+
end
|
11
|
+
|
12
|
+
it "can be configured" do
|
13
|
+
Safely::Backtrace.should respond_to(:trace_directory)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "can be enabled" do
|
17
|
+
Safely::Backtrace.enable!
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should log a backtrace on unsafe shutdown" do
|
21
|
+
`ruby #{File.expand_path('../backtrace/unsafe.rb', __FILE__)}`
|
22
|
+
|
23
|
+
entries = Dir["#{@temp_dir}/backtrace-*.log"]
|
24
|
+
entries.should_not be_empty
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should not log a backtrace on a safe shutdown" do
|
28
|
+
`ruby #{File.expand_path('../backtrace/safe.rb', __FILE__)}`
|
29
|
+
|
30
|
+
entries = Dir["#{@temp_dir}/backtrace-*.log"]
|
31
|
+
entries.should be_empty
|
32
|
+
end
|
33
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: safely
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.3.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Kenneth Kalmer
|
@@ -120,6 +120,7 @@ files:
|
|
120
120
|
- Rakefile
|
121
121
|
- VERSION
|
122
122
|
- lib/safely.rb
|
123
|
+
- lib/safely/backtrace.rb
|
123
124
|
- lib/safely/config.rb
|
124
125
|
- lib/safely/mixin.rb
|
125
126
|
- lib/safely/strategy.rb
|
@@ -127,6 +128,9 @@ files:
|
|
127
128
|
- lib/safely/strategy/log.rb
|
128
129
|
- lib/safely/strategy/mail.rb
|
129
130
|
- safely.gemspec
|
131
|
+
- spec/backtrace/safe.rb
|
132
|
+
- spec/backtrace/unsafe.rb
|
133
|
+
- spec/backtrace_spec.rb
|
130
134
|
- spec/config_spec.rb
|
131
135
|
- spec/safely_spec.rb
|
132
136
|
- spec/spec_helper.rb
|
@@ -147,7 +151,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
147
151
|
requirements:
|
148
152
|
- - ">="
|
149
153
|
- !ruby/object:Gem::Version
|
150
|
-
hash: -
|
154
|
+
hash: -1107195766842142569
|
151
155
|
segments:
|
152
156
|
- 0
|
153
157
|
version: "0"
|
@@ -165,6 +169,9 @@ signing_key:
|
|
165
169
|
specification_version: 3
|
166
170
|
summary: Safely run your code, keep track of exceptions
|
167
171
|
test_files:
|
172
|
+
- spec/backtrace/safe.rb
|
173
|
+
- spec/backtrace/unsafe.rb
|
174
|
+
- spec/backtrace_spec.rb
|
168
175
|
- spec/config_spec.rb
|
169
176
|
- spec/safely_spec.rb
|
170
177
|
- spec/spec_helper.rb
|