structured-event-logger 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,11 +4,11 @@ class StructuredEventLogger
4
4
 
5
5
  class Error < ::StandardError; end
6
6
 
7
- class EndpointException < StructuredEventLogger::Error
8
- attr_reader :name, :wrapped_exception
9
- def initialize(name, wrapped_exception)
10
- @name, @wrapped_exception = name, wrapped_exception
11
- super("Endpoint #{name} failed - #{wrapped_exception.class.name}: #{wrapped_exception.message}")
7
+ class EventHandlingException < StructuredEventLogger::Error
8
+ attr_reader :exceptions
9
+ def initialize(scope, name, exceptions)
10
+ @scope, @name, @exceptions = scope, name, exceptions
11
+ super("Failed to submit the #{scope}/#{name} event to the following endpoints: #{exceptions.keys.join(", ")}")
12
12
  end
13
13
  end
14
14
 
@@ -25,7 +25,7 @@ class StructuredEventLogger
25
25
 
26
26
  def event(scope, event, content = {})
27
27
  log_event scope, event, flatten_hash(content)
28
- rescue EndpointException => e
28
+ rescue EventHandlingException => e
29
29
  error_handler.call(e)
30
30
  end
31
31
 
@@ -53,13 +53,16 @@ class StructuredEventLogger
53
53
  record.update(event_name: event, event_scope: scope, event_uuid: SecureRandom.uuid, event_timestamp: Time.now.utc)
54
54
  record.update(hash)
55
55
 
56
+ exceptions = {}
56
57
  endpoints.each do |name, endpoint|
57
58
  begin
58
59
  endpoint.call(scope, event, hash, record)
59
60
  rescue => e
60
- raise EndpointException.new(name, e)
61
+ exceptions[name] = e
61
62
  end
62
63
  end
64
+
65
+ raise EventHandlingException.new(scope, event, exceptions) unless exceptions.empty?
63
66
  end
64
67
 
65
68
  def thread_key
@@ -1,3 +1,3 @@
1
1
  class StructuredEventLogger
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -135,28 +135,32 @@ class StructuredEventLoggerTest < Minitest::Test
135
135
 
136
136
  def test_should_fail_when_syslog_message_is_too_large
137
137
  @event_logger.endpoints[:syslog] = StructuredEventLogger::Syslogger.new
138
- assert_raises(StructuredEventLogger::EndpointException) do
138
+ assert_raises(StructuredEventLogger::EventHandlingException) do
139
139
  @event_logger.event(:test, :syslog, message: 'a' * (64 * 1024 + 1))
140
140
  end
141
141
  end
142
142
 
143
- def test_should_execute_a_custom_error_handler_on_failure
143
+ def test_should_raise_exception_when_endpoint_fails
144
144
  @event_logger.endpoints[:failer] = proc { raise "FAIL" }
145
+ assert_raises(StructuredEventLogger::EventHandlingException) do
146
+ @event_logger.event(:test, :fail)
147
+ end
148
+ end
149
+
150
+ def test_should_execute_a_custom_error_handler_on_failure
151
+ @event_logger.endpoints[:failer1] = proc { raise "FAIL" }
152
+ @event_logger.endpoints[:failer2] = proc { raise "FAIL" }
145
153
  @event_logger.error_handler = mock()
146
154
  @event_logger.error_handler.expects(:call).with do |exception|
147
- assert_kind_of StructuredEventLogger::EndpointException, exception
148
- assert_equal 'FAIL', exception.wrapped_exception.message
149
- assert_equal 'Endpoint failer failed - RuntimeError: FAIL', exception.message
155
+ assert_kind_of StructuredEventLogger::EventHandlingException, exception
156
+ assert_equal 'Failed to submit the test/fail event to the following endpoints: failer1, failer2', exception.message
157
+ assert_equal 2, exception.exceptions.size
158
+ assert_equal 'FAIL', exception.exceptions[:failer1].message
159
+ assert_kind_of RuntimeError, exception.exceptions[:failer2]
150
160
  end
151
161
  @event_logger.event(:test, :fail)
152
162
  end
153
163
 
154
- def test_should_raise_exception_when_endpoint_fails
155
- @event_logger.endpoints[:failer] = proc { raise "FAIL" }
156
- assert_raises(StructuredEventLogger::EndpointException) do
157
- @event_logger.event(:test, :fail)
158
- end
159
- end
160
164
 
161
165
  private
162
166
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: structured-event-logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2013-08-19 00:00:00.000000000 Z
15
+ date: 2013-08-20 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: activesupport