errlog 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/errlog/context.rb +23 -19
- data/lib/errlog/version.rb +1 -1
- data/spec/errlog_spec.rb +63 -49
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11d79f46d2df12286b3049c79c7229ee4f694ccb
|
4
|
+
data.tar.gz: 12b6ebffab66595105892bc245bc7048e72635de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0610be3f9b72943a602bfe8d537a00f881300693c2d72f6932d7e0a9fa967daf85fbe5741dc9883c310b4bd2af61ea99140d90e04d6f3b4a7850656088f22a49
|
7
|
+
data.tar.gz: 6443751a6535f965db8538c1ba8fdf3d55fb4c0ff6919c4bda1a5c7cd442d0e5ca9c2594748677ff7946cd89fbc2dc4476015d57e9970045cee0c14a69d4e8eb
|
data/lib/errlog/context.rb
CHANGED
@@ -18,8 +18,7 @@ module Errlog
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def exception e, severity=Errlog::ERROR, &block
|
21
|
-
|
22
|
-
self.stack = e.backtrace
|
21
|
+
self.stack = e.backtrace
|
23
22
|
self.exception_class = e.class.name
|
24
23
|
report e.to_s, severity
|
25
24
|
end
|
@@ -36,31 +35,36 @@ module Errlog
|
|
36
35
|
|
37
36
|
def error text, details=nil, severity=Errlog::ERROR, &block
|
38
37
|
details and self.details = details
|
39
|
-
report text, severity
|
38
|
+
report text, severity, &block
|
40
39
|
end
|
41
40
|
|
42
41
|
def before_report &block
|
43
42
|
(@before_handlers ||= []) << block
|
44
43
|
end
|
45
44
|
|
46
|
-
def report text, severity = Errlog::ERROR
|
47
|
-
|
48
|
-
self.application ||= Errlog.application
|
49
|
-
self.time = Time.now
|
50
|
-
self.severity = severity
|
51
|
-
self.platform ||= Errlog.default_platform
|
52
|
-
self.stack ||= caller
|
53
|
-
self.text = text
|
45
|
+
def report text, severity = Errlog::ERROR
|
46
|
+
yield self if block_given?
|
54
47
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
48
|
+
unless Errlog.configured?
|
49
|
+
STDERR.puts 'Errlog is not configured. Use Errlog.config'
|
50
|
+
else
|
51
|
+
self.application ||= Errlog.application
|
52
|
+
self.time = Time.now
|
53
|
+
self.severity = severity
|
54
|
+
self.platform ||= Errlog.default_platform
|
55
|
+
self.stack ||= caller
|
56
|
+
self.text = text
|
60
57
|
|
61
|
-
|
62
|
-
|
63
|
-
|
58
|
+
if @before_handlers
|
59
|
+
@before_handlers.each { |h|
|
60
|
+
h.call self
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
@log_records and self.log = @log_records.inject([]) { |all, x| all << x; all }.sort { |x, y| x[1] <=> y[1] }
|
65
|
+
Errlog.rails? and self.rails_root = Rails.root.to_s
|
66
|
+
Errlog.post self.to_hash
|
67
|
+
end
|
64
68
|
end
|
65
69
|
|
66
70
|
MAX_LOG_LINES = 100
|
data/lib/errlog/version.rb
CHANGED
data/spec/errlog_spec.rb
CHANGED
@@ -8,62 +8,78 @@ require 'stringio'
|
|
8
8
|
describe Errlog do
|
9
9
|
|
10
10
|
context 'configured' do
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'should have context' do
|
17
|
-
Errlog.context.value = 'test'
|
18
|
-
Errlog.context.value.should == 'test'
|
19
|
-
Errlog.clear_context
|
20
|
-
Errlog.context.value.should == nil
|
21
|
-
end
|
22
|
-
|
23
|
-
# This spec checks the whole chain - protect, exception, report, but does not check post
|
24
|
-
it 'should provide protection' do
|
25
|
-
Errlog.should_receive(:post).exactly(3).times do |payload|
|
26
|
-
payload = Hashie::Mash.new payload
|
27
|
-
payload.should_not be_nil
|
28
|
-
payload.stack[0].should =~ /errlog_spec/
|
29
|
-
payload.text.should == 'TestError'
|
30
|
-
payload.time.should be_within(5000).of(Time.now)
|
31
|
-
payload.component_name.should == 'test'
|
32
|
-
payload.test.should == '123'
|
11
|
+
before :each do
|
12
|
+
Errlog.configure 'TheTestId', '1234567890123456'
|
13
|
+
@packager = Errlog.packager 'TheTestId', '1234567890123456'
|
33
14
|
end
|
34
15
|
|
35
|
-
|
16
|
+
it 'should have context' do
|
17
|
+
Errlog.context.value = 'test'
|
18
|
+
Errlog.context.value.should == 'test'
|
36
19
|
Errlog.clear_context
|
37
|
-
|
38
|
-
raise 'TestError'
|
20
|
+
Errlog.context.value.should == nil
|
39
21
|
end
|
40
22
|
|
41
|
-
|
42
|
-
|
23
|
+
# This spec checks the whole chain - protect, exception, report, but does not check post
|
24
|
+
it 'should provide protection' do
|
25
|
+
Errlog.should_receive(:post).exactly(3).times do |payload|
|
26
|
+
payload = Hashie::Mash.new payload
|
27
|
+
payload.should_not be_nil
|
28
|
+
payload.stack[0].should =~ /errlog_spec/
|
29
|
+
payload.text.should == 'TestError'
|
30
|
+
payload.time.should be_within(5000).of(Time.now)
|
31
|
+
payload.component_name.should == 'test'
|
32
|
+
payload.test.should == '123'
|
33
|
+
end
|
34
|
+
|
35
|
+
Errlog.protect 'test' do |ctx|
|
36
|
+
Errlog.clear_context
|
43
37
|
ctx.test = '123'
|
44
38
|
raise 'TestError'
|
45
39
|
end
|
46
|
-
}.should raise_error
|
47
40
|
|
48
|
-
|
49
|
-
|
50
|
-
|
41
|
+
-> {
|
42
|
+
Errlog.protect_rethrow 'test' do |ctx|
|
43
|
+
ctx.test = '123'
|
44
|
+
raise 'TestError'
|
45
|
+
end
|
46
|
+
}.should raise_error
|
51
47
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
48
|
+
Errlog.context.test = '123'
|
49
|
+
Errlog.report 'TestError'
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should provide logs' do
|
53
|
+
Errlog.should_receive(:post).exactly(1).times do |payload|
|
54
|
+
payload = Hashie::Mash.new payload
|
55
|
+
payload.text.should == 'LogTest'
|
56
|
+
payload.log.length.should == 2
|
57
|
+
payload.log[0][3].should == 'test info'
|
58
|
+
payload.log[1][3].should == 'test warning'
|
59
|
+
end
|
60
|
+
sio = StringIO.new
|
61
|
+
l1 = Errlog::ChainLogger.new
|
62
|
+
l2 = Errlog::ChainLogger.new Logger.new(sio)
|
63
|
+
l1.info 'test info'
|
64
|
+
l2.warn 'test warning'
|
65
|
+
Errlog.report 'LogTest', Errlog::TRACE
|
66
|
+
sio.string.should match(/W, \[.*\] WARN -- : test warning/)
|
59
67
|
end
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
68
|
+
|
69
|
+
it 'should provide data in context' do
|
70
|
+
Errlog.clear_context
|
71
|
+
Errlog.should_receive(:post).exactly(1).times do |payload|
|
72
|
+
payload = Hashie::Mash.new payload
|
73
|
+
payload.text.should == 'ParamTest'
|
74
|
+
payload.test1.should == 'test1 data'
|
75
|
+
payload.test2.should == 'test2 data'
|
76
|
+
end
|
77
|
+
Errlog.context.test1 = 'test1 data'
|
78
|
+
Errlog.error "ParamTest" do |c|
|
79
|
+
c.test2 = 'test2 data'
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
67
83
|
end
|
68
84
|
|
69
85
|
it 'should provide constants' do
|
@@ -77,7 +93,7 @@ describe Errlog do
|
|
77
93
|
is_warning?(Errlog::ERROR).should_not be_true
|
78
94
|
is_warning?(Errlog::WARNING).should be_true
|
79
95
|
is_warning?(Errlog::TRACE).should_not be_true
|
80
|
-
|
96
|
+
|
81
97
|
is_trace?(Errlog::ERROR).should_not be_true
|
82
98
|
is_trace?(Errlog::WARNING).should_not be_true
|
83
99
|
is_trace?(Errlog::TRACE).should be_true
|
@@ -87,10 +103,8 @@ describe Errlog do
|
|
87
103
|
Errlog.severity_name(Errlog::TRACE).should == 'trace'
|
88
104
|
end
|
89
105
|
|
90
|
-
end
|
91
|
-
|
92
106
|
it 'should work fine when not configured' do
|
93
|
-
expect { Errlog.error "Some error" }.
|
107
|
+
expect { Errlog.error "Some error" }.to_not raise_error
|
94
108
|
expect {
|
95
109
|
Errlog.protect_rethrow {
|
96
110
|
raise "test"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: errlog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sergeych
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-04-
|
11
|
+
date: 2013-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: boss-protocol
|