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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 742e90a6c45ef372d95f07e88a6842095748d109
4
- data.tar.gz: 515ee1ca2103aee10a0fec3036dba273f62f9bd3
3
+ metadata.gz: 11d79f46d2df12286b3049c79c7229ee4f694ccb
4
+ data.tar.gz: 12b6ebffab66595105892bc245bc7048e72635de
5
5
  SHA512:
6
- metadata.gz: 5e7ed76719a32f26a44ba923c456e100203c3b772d9f66fb423c92b59d65a19498920c50399302e0af96b857869c351f691552543447ccfbaff2432b26ca6219
7
- data.tar.gz: 12be1679456863fa78013bdf145e3bafe0394e1b27f94ec2abfaa48200669d0c124fafc90e4127a62a613562221e01b31e5bbdab8af0086d0c1bbc6e220f5eae
6
+ metadata.gz: 0610be3f9b72943a602bfe8d537a00f881300693c2d72f6932d7e0a9fa967daf85fbe5741dc9883c310b4bd2af61ea99140d90e04d6f3b4a7850656088f22a49
7
+ data.tar.gz: 6443751a6535f965db8538c1ba8fdf3d55fb4c0ff6919c4bda1a5c7cd442d0e5ca9c2594748677ff7946cd89fbc2dc4476015d57e9970045cee0c14a69d4e8eb
@@ -18,8 +18,7 @@ module Errlog
18
18
  end
19
19
 
20
20
  def exception e, severity=Errlog::ERROR, &block
21
- raise unless Errlog.configured?
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, &block
47
- raise 'Errlog is not configured. Use Errlog.config' unless Errlog.configured?
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
- if @before_handlers
56
- @before_handlers.each { |h|
57
- h.call self
58
- }
59
- end
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
- @log_records and self.log = @log_records.inject([]){ |all,x| all << x; all}.sort { |x,y| x[1] <=> y[1] }
62
- Errlog.rails? and self.rails_root = Rails.root.to_s
63
- Errlog.post(self.to_hash, &block)
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
@@ -1,3 +1,3 @@
1
1
  module Errlog
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
3
3
  end
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
- before :each do
12
- Errlog.configure 'TheTestId', '1234567890123456'
13
- @packager = Errlog.packager 'TheTestId', '1234567890123456'
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
- Errlog.protect 'test' do |ctx|
16
+ it 'should have context' do
17
+ Errlog.context.value = 'test'
18
+ Errlog.context.value.should == 'test'
36
19
  Errlog.clear_context
37
- ctx.test = '123'
38
- raise 'TestError'
20
+ Errlog.context.value.should == nil
39
21
  end
40
22
 
41
- -> {
42
- Errlog.protect_rethrow 'test' do |ctx|
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
- Errlog.context.test = '123'
49
- Errlog.report 'TestError'
50
- end
41
+ -> {
42
+ Errlog.protect_rethrow 'test' do |ctx|
43
+ ctx.test = '123'
44
+ raise 'TestError'
45
+ end
46
+ }.should raise_error
51
47
 
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'
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
- 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/)
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" }.to raise_error(StandardError, 'Errlog is not configured. Use Errlog.config')
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.2
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-05 00:00:00.000000000 Z
11
+ date: 2013-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: boss-protocol