structured-event-logger 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MTUxNWZjZjQyMTlhYjI2MjgyMjIwM2U4ZmI3MzM2MjkwMzQ0NzViMg==
5
+ data.tar.gz: !binary |-
6
+ YTk4YzRkYmRkOGM4Y2U3OWQ1OWMyMWE3NTVjYjlmMDU3YmI0NjAxMg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NmYzM2RiMWMxZDE2NTMyNzI4NTY5MTdiNmRmYjY5NjFmNzNiNTk4YTg2YTcw
10
+ YmEyMzcxYzlhZWM3Y2I5MTdlMmExMTM0OWI3NTJjYWFiMDFiMzhlZmJjMzhi
11
+ OTMxNTc2YWUwY2NiMmVmZWQxZTQ4NTA1MGFmY2U3NWM1NTM5NTE=
12
+ data.tar.gz: !binary |-
13
+ MzcyYmJmNWMyYTU0MmIyODE0ZTI5YTg0NjE3MmQyOGMwMmRlMmEyMDYwNzgy
14
+ ODA1NmZlNDdkMDNiZjkzM2MxZTI0ZWEzMmEwNjMwNTAzYzBlM2MyNGIxNzlm
15
+ NTBiMDZkYzNhOTI4ZTgxZTZjOWQwNzFlYWY4NWNiMWJmZjY4NWQ=
@@ -13,6 +13,8 @@ class StructuredEventLogger
13
13
  end
14
14
 
15
15
  attr_reader :endpoints, :default_context
16
+
17
+ attr_accessor :only
16
18
  attr_accessor :error_handler
17
19
 
18
20
  def initialize(endpoints = {})
@@ -20,10 +22,12 @@ class StructuredEventLogger
20
22
 
21
23
  @thread_contexts = {}
22
24
  @default_context = {}
25
+
23
26
  @error_handler = lambda { |exception| raise(exception) }
24
27
  end
25
28
 
26
29
  def event(scope, event, content = {})
30
+ return unless @only.nil? || @only.call(scope, event, content)
27
31
  log_event scope, event, flatten_hash(content)
28
32
  rescue EventHandlingException => e
29
33
  error_handler.call(e)
@@ -1,3 +1,3 @@
1
1
  class StructuredEventLogger
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -4,15 +4,15 @@ require 'stringio'
4
4
  class StructuredEventLoggerTest < Minitest::Test
5
5
  def setup
6
6
  ActiveSupport::LogSubscriber.colorize_logging = false
7
-
7
+
8
8
  @unstructured_logger = Logger.new(@nonstructured_io = StringIO.new)
9
9
  @unstructured_logger.formatter = proc { |_, _, _, msg| "#{msg}\n" }
10
-
10
+
11
11
  @event_logger = StructuredEventLogger.new(
12
12
  logger: StructuredEventLogger::HumanReadableLogger.new(@unstructured_logger),
13
13
  json: StructuredEventLogger::JsonWriter.new(@json_io = StringIO.new)
14
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')
18
18
  Syslog.open('test_structured_event_logger') unless Syslog.opened?
@@ -70,10 +70,10 @@ class StructuredEventLoggerTest < Minitest::Test
70
70
  end
71
71
 
72
72
  def test_should_log_to_current_context
73
- Thread.new do
73
+ Thread.new do
74
74
  @event_logger.context[:request_id] = '1'
75
75
 
76
- Thread.new do
76
+ Thread.new do
77
77
  @event_logger.context[:request_id] = '2'
78
78
  @event_logger.event :render, :error
79
79
  end.join
@@ -145,7 +145,7 @@ class StructuredEventLoggerTest < Minitest::Test
145
145
  assert_raises(StructuredEventLogger::EventHandlingException) do
146
146
  @event_logger.event(:test, :fail)
147
147
  end
148
- end
148
+ end
149
149
 
150
150
  def test_should_execute_a_custom_error_handler_on_failure
151
151
  @event_logger.endpoints[:failer1] = proc { raise "FAIL" }
@@ -161,8 +161,21 @@ class StructuredEventLoggerTest < Minitest::Test
161
161
  @event_logger.event(:test, :fail)
162
162
  end
163
163
 
164
+ def test_only
165
+ @event_logger.only = lambda { |*args| return false }
166
+ @event_logger.event(:dont_do_it, :foobar)
167
+ assert_nil last_event
164
168
 
165
- private
169
+ @event_logger.only = lambda{ |scope, event, content| scope == :do_it }
170
+ @event_logger.event(:dont_do_it, :foobar)
171
+ assert_nil last_event
172
+
173
+ @event_logger.only = lambda{ |scope, event, content| scope == :do_it }
174
+ @event_logger.event(:do_it, :foobar)
175
+ assert_last_event_contains_value "do_it", "event_scope"
176
+ end
177
+
178
+ private
166
179
 
167
180
  def assert_last_event_contains_value(value, key)
168
181
  assert_equal value, last_parsed_event[key.to_s]
@@ -172,7 +185,11 @@ class StructuredEventLoggerTest < Minitest::Test
172
185
  assert !last_parsed_event.has_key?(key.to_s)
173
186
  end
174
187
 
188
+ def last_event
189
+ @json_io.string.lines.entries[-1]
190
+ end
191
+
175
192
  def last_parsed_event
176
- JSON.parse(@json_io.string.lines.entries[-1])
193
+ JSON.parse(last_event)
177
194
  end
178
195
  end
metadata CHANGED
@@ -1,8 +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.1
5
- prerelease:
4
+ version: 0.1.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Emilie Noel
@@ -12,12 +11,11 @@ authors:
12
11
  autorequire:
13
12
  bindir: bin
14
13
  cert_chain: []
15
- date: 2013-08-20 00:00:00.000000000 Z
14
+ date: 2013-10-08 00:00:00.000000000 Z
16
15
  dependencies:
17
16
  - !ruby/object:Gem::Dependency
18
17
  name: activesupport
19
18
  requirement: !ruby/object:Gem::Requirement
20
- none: false
21
19
  requirements:
22
20
  - - ~>
23
21
  - !ruby/object:Gem::Version
@@ -25,7 +23,6 @@ dependencies:
25
23
  type: :runtime
26
24
  prerelease: false
27
25
  version_requirements: !ruby/object:Gem::Requirement
28
- none: false
29
26
  requirements:
30
27
  - - ~>
31
28
  - !ruby/object:Gem::Version
@@ -33,7 +30,6 @@ dependencies:
33
30
  - !ruby/object:Gem::Dependency
34
31
  name: multi_json
35
32
  requirement: !ruby/object:Gem::Requirement
36
- none: false
37
33
  requirements:
38
34
  - - ! '>='
39
35
  - !ruby/object:Gem::Version
@@ -41,7 +37,6 @@ dependencies:
41
37
  type: :runtime
42
38
  prerelease: false
43
39
  version_requirements: !ruby/object:Gem::Requirement
44
- none: false
45
40
  requirements:
46
41
  - - ! '>='
47
42
  - !ruby/object:Gem::Version
@@ -49,7 +44,6 @@ dependencies:
49
44
  - !ruby/object:Gem::Dependency
50
45
  name: bundler
51
46
  requirement: !ruby/object:Gem::Requirement
52
- none: false
53
47
  requirements:
54
48
  - - ~>
55
49
  - !ruby/object:Gem::Version
@@ -57,7 +51,6 @@ dependencies:
57
51
  type: :development
58
52
  prerelease: false
59
53
  version_requirements: !ruby/object:Gem::Requirement
60
- none: false
61
54
  requirements:
62
55
  - - ~>
63
56
  - !ruby/object:Gem::Version
@@ -65,7 +58,6 @@ dependencies:
65
58
  - !ruby/object:Gem::Dependency
66
59
  name: rake
67
60
  requirement: !ruby/object:Gem::Requirement
68
- none: false
69
61
  requirements:
70
62
  - - ! '>='
71
63
  - !ruby/object:Gem::Version
@@ -73,7 +65,6 @@ dependencies:
73
65
  type: :development
74
66
  prerelease: false
75
67
  version_requirements: !ruby/object:Gem::Requirement
76
- none: false
77
68
  requirements:
78
69
  - - ! '>='
79
70
  - !ruby/object:Gem::Version
@@ -81,7 +72,6 @@ dependencies:
81
72
  - !ruby/object:Gem::Dependency
82
73
  name: minitest
83
74
  requirement: !ruby/object:Gem::Requirement
84
- none: false
85
75
  requirements:
86
76
  - - ~>
87
77
  - !ruby/object:Gem::Version
@@ -89,7 +79,6 @@ dependencies:
89
79
  type: :development
90
80
  prerelease: false
91
81
  version_requirements: !ruby/object:Gem::Requirement
92
- none: false
93
82
  requirements:
94
83
  - - ~>
95
84
  - !ruby/object:Gem::Version
@@ -97,7 +86,6 @@ dependencies:
97
86
  - !ruby/object:Gem::Dependency
98
87
  name: mocha
99
88
  requirement: !ruby/object:Gem::Requirement
100
- none: false
101
89
  requirements:
102
90
  - - ! '>='
103
91
  - !ruby/object:Gem::Version
@@ -105,7 +93,6 @@ dependencies:
105
93
  type: :development
106
94
  prerelease: false
107
95
  version_requirements: !ruby/object:Gem::Requirement
108
- none: false
109
96
  requirements:
110
97
  - - ! '>='
111
98
  - !ruby/object:Gem::Version
@@ -135,27 +122,26 @@ files:
135
122
  homepage: https://github.com/Shopify/structured-event-logger
136
123
  licenses:
137
124
  - MIT
125
+ metadata: {}
138
126
  post_install_message:
139
127
  rdoc_options: []
140
128
  require_paths:
141
129
  - lib
142
130
  required_ruby_version: !ruby/object:Gem::Requirement
143
- none: false
144
131
  requirements:
145
132
  - - ! '>='
146
133
  - !ruby/object:Gem::Version
147
134
  version: '0'
148
135
  required_rubygems_version: !ruby/object:Gem::Requirement
149
- none: false
150
136
  requirements:
151
137
  - - ! '>='
152
138
  - !ruby/object:Gem::Version
153
139
  version: '0'
154
140
  requirements: []
155
141
  rubyforge_project:
156
- rubygems_version: 1.8.23
142
+ rubygems_version: 2.1.4
157
143
  signing_key:
158
- specification_version: 3
144
+ specification_version: 4
159
145
  summary: Structured event logger that writes events to both a human readable log and
160
146
  a JSON formatted log
161
147
  test_files: