structured-event-logger 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,11 +4,11 @@ class StructuredEventLogger
|
|
4
4
|
|
5
5
|
class Error < ::StandardError; end
|
6
6
|
|
7
|
-
class
|
8
|
-
attr_reader :
|
9
|
-
def initialize(name,
|
10
|
-
@name, @
|
11
|
-
super("
|
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
|
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
|
-
|
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
|
@@ -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::
|
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
|
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::
|
148
|
-
assert_equal '
|
149
|
-
assert_equal
|
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.
|
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-
|
15
|
+
date: 2013-08-20 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: activesupport
|