conrad 2.1.0 → 2.2.0

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
  SHA256:
3
- metadata.gz: 178acce18a6f1cd584f74d8bcf4d7d181f6d240ec7e3df10c644aa894f4e9b7b
4
- data.tar.gz: 88bd011a135527d7068b85ebf94c9b037205622d475798ae029cf9f2786d446e
3
+ metadata.gz: dca0b05c54f60645fece80d8226d43d6130afb47aac653d8bb92090b619c7812
4
+ data.tar.gz: 26a24ce8ec5288ab2847fda11442c13dbba14addd883dd2931d32ef1da240222
5
5
  SHA512:
6
- metadata.gz: 60998b354a36ac3e14160805d012f323c2362e20ffd92eee9c3a65e605af6ecd394d40f8f649e39cdec222de701faea8b6dcc266aedf6c5b3bebe063c5866dd3
7
- data.tar.gz: 48e969b3e326cf32dc6270412840025077443abbe8a71ad62cd6f88ca3eeff6519608bbfced6851df7f3a3296a3bca7e48808eaf894003d264e23a62c9f4c659
6
+ metadata.gz: 3f9023ef66bb257ad4d9ceaa25b4ce63e646128c67e11de7fda8a765622235eefebfc83019a6ff4f0349ce0134b19793c689c0319f07e9e4e2af9e3f5982442d
7
+ data.tar.gz: fa8f34c73693be7666ee7ccadd9ba54f69d716c197ced407d5788a2a0205dea7755771fd4d359e2362befff766caae9173e89fb183fb757ec0e230c0b335a7c2
@@ -37,6 +37,10 @@ module Conrad
37
37
  # instead be sent one-by-one. Defaults to false.
38
38
  attr_accessor :default_emit_as_batch
39
39
 
40
+ # Allows assigning a default logger to use for logging out of the gem.
41
+ # Should respond to #debug, #info, #warn, #error, and #fatal.
42
+ attr_accessor :default_logger
43
+
40
44
  # @return [Conrad::Collector] the collector for a given Thread that is
41
45
  # currently active
42
46
  def current
@@ -79,6 +83,9 @@ module Conrad
79
83
  attr_accessor :emit_as_batch
80
84
  alias emit_as_batch? emit_as_batch
81
85
 
86
+ # Logger object used for sending log events
87
+ attr_accessor :logger
88
+
82
89
  # @param processors [Array<#call>] set of processors to run. Defaults to
83
90
  # processors as configured for the class.
84
91
  # @param formatter [#call] Formatter to use. Defaults to
@@ -91,7 +98,8 @@ module Conrad
91
98
  processors: self.class.default_processors,
92
99
  formatter: self.class.default_formatter,
93
100
  emitter: self.class.default_emitter,
94
- emit_as_batch: self.class.default_emit_as_batch
101
+ emit_as_batch: self.class.default_emit_as_batch,
102
+ logger: self.class.default_logger
95
103
  )
96
104
  @events = []
97
105
  @event_metadata = {}
@@ -100,6 +108,7 @@ module Conrad
100
108
  @formatter = formatter
101
109
  @emitter = emitter
102
110
  @emit_as_batch = emit_as_batch
111
+ @logger = logger
103
112
  end
104
113
 
105
114
  # Adds an event to the Collector to be audited at a later time. The
@@ -123,13 +132,18 @@ module Conrad
123
132
 
124
133
  # Records the events currently in the collection then clears the state of
125
134
  # the Collector by emptying the events stack and clearing out the metadata.
135
+ #
136
+ # @note Currently for emitting individual events, if an error is raised then
137
+ # a log message will be attempted using the configured logger. For batch
138
+ # emitted events, the error will be allowed to bubble up. This is to
139
+ # prevent the unexpected loss of events if a single one is malformed.
126
140
  def record_events
127
141
  if emit_as_batch?
128
142
  record_events_as_batch
129
143
  else
130
144
  record_individual_events
131
145
  end
132
-
146
+ ensure
133
147
  reset_state
134
148
  end
135
149
 
@@ -140,6 +154,15 @@ module Conrad
140
154
  @processors = processors
141
155
  end
142
156
 
157
+ # Adds the given hash of data to the already existing event metadata
158
+ #
159
+ # @param new_metadata [Hash]
160
+ #
161
+ # @return nothing
162
+ def add_metadata(new_metadata)
163
+ event_metadata.merge!(new_metadata)
164
+ end
165
+
143
166
  private
144
167
 
145
168
  attr_reader :processor_stack
@@ -156,7 +179,11 @@ module Conrad
156
179
 
157
180
  def record_individual_events
158
181
  events.each do |event|
159
- emitter.call(event)
182
+ begin
183
+ emitter.call(event)
184
+ rescue StandardError => e
185
+ write_log(:error, e)
186
+ end
160
187
  end
161
188
  end
162
189
 
@@ -164,5 +191,11 @@ module Conrad
164
191
  event_metadata.clear
165
192
  events.clear
166
193
  end
194
+
195
+ def write_log(level, data)
196
+ return unless logger
197
+
198
+ logger.public_send(level, data)
199
+ end
167
200
  end
168
201
  end
@@ -1,5 +1,5 @@
1
1
  # :nodoc:
2
2
  module Conrad
3
3
  # :nodoc:
4
- VERSION = '2.1.0'.freeze
4
+ VERSION = '2.2.0'.freeze
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: conrad
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathon Anderson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-11 00:00:00.000000000 Z
11
+ date: 2019-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk