structured-event-logger 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
data/README.md
CHANGED
@@ -22,10 +22,10 @@ Or install it yourself as:
|
|
22
22
|
# Creating an instance of a StructuredEventLogger with several endpoints.
|
23
23
|
# The listeners provided to the constructors should respond to #log_event.
|
24
24
|
json_io = File.open(Rails.root.join("log", "event.log"), "a")
|
25
|
-
event_logger = StructuredEventLogger.new(
|
26
|
-
StructuredEventLogger::HumanReadableLogger.new(Rails.logger),
|
27
|
-
StructuredEventLogger::JsonWriter.new(json_io)
|
28
|
-
|
25
|
+
event_logger = StructuredEventLogger.new(
|
26
|
+
logger: StructuredEventLogger::HumanReadableLogger.new(Rails.logger),
|
27
|
+
json: StructuredEventLogger::JsonWriter.new(json_io)
|
28
|
+
)
|
29
29
|
|
30
30
|
# Basic usage
|
31
31
|
event_logger.event('scope', event, field: 'value', other_field: 'other value')
|
@@ -3,7 +3,7 @@ require 'securerandom'
|
|
3
3
|
class StructuredEventLogger
|
4
4
|
attr_reader :endpoints, :default_context
|
5
5
|
|
6
|
-
def initialize(endpoints =
|
6
|
+
def initialize(endpoints = {})
|
7
7
|
@endpoints = endpoints
|
8
8
|
|
9
9
|
@thread_contexts = {}
|
@@ -38,11 +38,11 @@ class StructuredEventLogger
|
|
38
38
|
record.update(event_name: event, event_scope: scope, event_uuid: SecureRandom.uuid, event_timestamp: Time.now.utc)
|
39
39
|
record.update(hash)
|
40
40
|
|
41
|
-
endpoints.each do |endpoint|
|
41
|
+
endpoints.each do |name, endpoint|
|
42
42
|
begin
|
43
43
|
endpoint.call(scope, event, hash, record)
|
44
44
|
rescue => e
|
45
|
-
$stderr.write("Failed to submit event #{scope}/#{event} to #{endpoint
|
45
|
+
$stderr.write("Failed to submit event #{scope}/#{event} to #{name} endpoint: #{e.message}.\n")
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -8,10 +8,10 @@ class StructuredEventLoggerTest < Minitest::Test
|
|
8
8
|
@unstructured_logger = Logger.new(@nonstructured_io = StringIO.new)
|
9
9
|
@unstructured_logger.formatter = proc { |_, _, _, msg| "#{msg}\n" }
|
10
10
|
|
11
|
-
@event_logger = StructuredEventLogger.new(
|
12
|
-
StructuredEventLogger::HumanReadableLogger.new(@unstructured_logger),
|
13
|
-
StructuredEventLogger::JsonWriter.new(@json_io = StringIO.new)
|
14
|
-
|
11
|
+
@event_logger = StructuredEventLogger.new(
|
12
|
+
logger: StructuredEventLogger::HumanReadableLogger.new(@unstructured_logger),
|
13
|
+
json: StructuredEventLogger::JsonWriter.new(@json_io = StringIO.new)
|
14
|
+
)
|
15
15
|
|
16
16
|
Time.stubs(:now).returns(Time.parse('2012-01-01T05:00:00Z'))
|
17
17
|
SecureRandom.stubs(:uuid).returns('aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee')
|
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.0.
|
4
|
+
version: 0.0.6
|
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-19 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: activesupport
|