semantic_logger 3.2.1 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/semantic_logger.rb +22 -2
  4. data/lib/semantic_logger/appender/bugsnag.rb +2 -2
  5. data/lib/semantic_logger/appender/elasticsearch.rb +9 -1
  6. data/lib/semantic_logger/appender/file.rb +1 -1
  7. data/lib/semantic_logger/appender/graylog.rb +18 -21
  8. data/lib/semantic_logger/appender/honeybadger.rb +27 -12
  9. data/lib/semantic_logger/appender/http.rb +19 -11
  10. data/lib/semantic_logger/appender/mongodb.rb +23 -30
  11. data/lib/semantic_logger/appender/new_relic.rb +2 -2
  12. data/lib/semantic_logger/appender/splunk.rb +32 -21
  13. data/lib/semantic_logger/appender/splunk_http.rb +1 -3
  14. data/lib/semantic_logger/appender/syslog.rb +25 -10
  15. data/lib/semantic_logger/appender/tcp.rb +231 -0
  16. data/lib/semantic_logger/appender/udp.rb +106 -0
  17. data/lib/semantic_logger/appender/wrapper.rb +1 -1
  18. data/lib/semantic_logger/base.rb +9 -3
  19. data/lib/semantic_logger/formatters/base.rb +36 -0
  20. data/lib/semantic_logger/formatters/color.rb +13 -10
  21. data/lib/semantic_logger/formatters/default.rb +8 -5
  22. data/lib/semantic_logger/formatters/json.rb +10 -3
  23. data/lib/semantic_logger/formatters/raw.rb +13 -0
  24. data/lib/semantic_logger/formatters/syslog.rb +119 -0
  25. data/lib/semantic_logger/log.rb +7 -5
  26. data/lib/semantic_logger/loggable.rb +5 -0
  27. data/lib/semantic_logger/logger.rb +45 -10
  28. data/lib/semantic_logger/metrics/new_relic.rb +1 -1
  29. data/lib/semantic_logger/metrics/statsd.rb +5 -1
  30. data/lib/semantic_logger/metrics/udp.rb +80 -0
  31. data/lib/semantic_logger/semantic_logger.rb +23 -27
  32. data/lib/semantic_logger/subscriber.rb +127 -0
  33. data/lib/semantic_logger/version.rb +1 -1
  34. data/test/appender/elasticsearch_test.rb +6 -4
  35. data/test/appender/file_test.rb +12 -12
  36. data/test/appender/honeybadger_test.rb +7 -1
  37. data/test/appender/http_test.rb +4 -2
  38. data/test/appender/mongodb_test.rb +1 -2
  39. data/test/appender/splunk_http_test.rb +8 -6
  40. data/test/appender/splunk_test.rb +48 -45
  41. data/test/appender/syslog_test.rb +3 -3
  42. data/test/appender/tcp_test.rb +68 -0
  43. data/test/appender/udp_test.rb +61 -0
  44. data/test/appender/wrapper_test.rb +5 -5
  45. data/test/concerns/compatibility_test.rb +6 -6
  46. data/test/debug_as_trace_logger_test.rb +2 -2
  47. data/test/loggable_test.rb +2 -2
  48. data/test/logger_test.rb +48 -45
  49. metadata +13 -3
  50. data/lib/semantic_logger/appender/base.rb +0 -101
@@ -4,9 +4,13 @@ require_relative 'test_helper'
4
4
  class LoggerTest < Minitest::Test
5
5
  describe SemanticLogger::Logger do
6
6
  describe '.add_appender' do
7
+ before do
8
+ @appender = nil
9
+ end
10
+
7
11
  after do
8
- SemanticLogger.remove_appender(@appender) if @appender
9
- File.delete('sample.log') if File.exists?('sample.log')
12
+ SemanticLogger.remove_appender(@appender)
13
+ File.delete('sample.log') if File.exist?('sample.log')
10
14
  end
11
15
 
12
16
  it 'adds file appender' do
@@ -30,8 +34,8 @@ class LoggerTest < Minitest::Test
30
34
  end
31
35
 
32
36
  it 'adds symbol appender' do
33
- @appender = SemanticLogger.add_appender(appender: :http, url: 'http://localhost:8088/path')
34
- assert @appender.is_a?(SemanticLogger::Appender::Http), @appender.ai
37
+ @appender = SemanticLogger.add_appender(appender: :wrapper, logger: Logger.new(STDOUT))
38
+ assert @appender.is_a?(SemanticLogger::Appender::Wrapper), @appender.ai
35
39
  assert SemanticLogger.appenders.include?(@appender)
36
40
  end
37
41
 
@@ -52,8 +56,8 @@ class LoggerTest < Minitest::Test
52
56
  end
53
57
 
54
58
  it 'adds appender' do
55
- @appender = SemanticLogger.add_appender(appender: SemanticLogger::Appender::Http.new(url: 'http://localhost:8088/path'))
56
- assert @appender.is_a?(SemanticLogger::Appender::Http), @appender.ai
59
+ @appender = SemanticLogger.add_appender(appender: SemanticLogger::Appender::File.new(io: STDOUT))
60
+ assert @appender.is_a?(SemanticLogger::Appender::File), @appender.ai
57
61
  assert SemanticLogger.appenders.include?(@appender)
58
62
  end
59
63
 
@@ -67,7 +71,7 @@ class LoggerTest < Minitest::Test
67
71
  describe '.add_appender DEPRECATED' do
68
72
  after do
69
73
  SemanticLogger.remove_appender(@appender) if @appender
70
- File.delete('sample.log') if File.exists?('sample.log')
74
+ File.delete('sample.log') if File.exist?('sample.log')
71
75
  end
72
76
 
73
77
  it 'adds file appender' do
@@ -83,8 +87,8 @@ class LoggerTest < Minitest::Test
83
87
  end
84
88
 
85
89
  it 'adds appender' do
86
- @appender = SemanticLogger.add_appender(SemanticLogger::Appender::Http.new(url: 'http://localhost:8088/path'))
87
- assert @appender.is_a?(SemanticLogger::Appender::Http), @appender.ai
90
+ @appender = SemanticLogger.add_appender(SemanticLogger::Appender::File.new(io: STDOUT))
91
+ assert @appender.is_a?(SemanticLogger::Appender::File), @appender.ai
88
92
  assert SemanticLogger.appenders.include?(@appender)
89
93
  end
90
94
 
@@ -143,7 +147,7 @@ class LoggerTest < Minitest::Test
143
147
  it 'logs' do
144
148
  @logger.send(level, 'hello world', @hash) { 'Calculations' }
145
149
  SemanticLogger.flush
146
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}\] LoggerTest -- hello world -- Calculations -- #{@hash_str}/, @mock_logger.message
150
+ assert_match(/\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}\] LoggerTest -- hello world -- Calculations -- #{@hash_str}/, @mock_logger.message)
147
151
  end
148
152
 
149
153
  it 'exclude log messages using Proc filter' do
@@ -167,7 +171,7 @@ class LoggerTest < Minitest::Test
167
171
  SemanticLogger.stub(:backtrace_level_index, 0) do
168
172
  @logger.send(level, 'hello world', @hash) { 'Calculations' }
169
173
  SemanticLogger.flush
170
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}#{@file_name_reg_exp}\] LoggerTest -- hello world -- Calculations -- #{@hash_str}/, @mock_logger.message
174
+ assert_match(/\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}#{@file_name_reg_exp}\] LoggerTest -- hello world -- Calculations -- #{@hash_str}/, @mock_logger.message)
171
175
  end
172
176
  end
173
177
 
@@ -176,7 +180,7 @@ class LoggerTest < Minitest::Test
176
180
  exc = RuntimeError.new("Test")
177
181
  @logger.send(level, 'hello world', exc)
178
182
  SemanticLogger.flush
179
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}#{@file_name_reg_exp}\] LoggerTest -- hello world -- Exception: RuntimeError: Test/, @mock_logger.message
183
+ assert_match(/\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}#{@file_name_reg_exp}\] LoggerTest -- hello world -- Exception: RuntimeError: Test/, @mock_logger.message)
180
184
  end
181
185
  end
182
186
 
@@ -185,21 +189,21 @@ class LoggerTest < Minitest::Test
185
189
  hash_str = hash.inspect.sub('{', '\{').sub('}', '\}')
186
190
  @logger.send(level, 'Hello world', hash)
187
191
  SemanticLogger.flush
188
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}\] LoggerTest -- Hello world -- #{hash_str}/, @mock_logger.message
192
+ assert_match(/\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}\] LoggerTest -- Hello world -- #{hash_str}/, @mock_logger.message)
189
193
  end
190
194
 
191
195
  it 'does not log an empty payload' do
192
196
  hash = {}
193
197
  @logger.send(level, 'Hello world', hash)
194
198
  SemanticLogger.flush
195
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}\] LoggerTest -- Hello world/, @mock_logger.message
199
+ assert_match(/\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}\] LoggerTest -- Hello world/, @mock_logger.message)
196
200
  end
197
201
 
198
202
  describe 'hash only argument' do
199
203
  it 'logs message' do
200
204
  @logger.send(level, message: 'Hello world')
201
205
  SemanticLogger.flush
202
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}\] LoggerTest -- Hello world/, @mock_logger.message
206
+ assert_match(/\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}\] LoggerTest -- Hello world/, @mock_logger.message)
203
207
  end
204
208
 
205
209
  it 'logs payload and message' do
@@ -207,7 +211,7 @@ class LoggerTest < Minitest::Test
207
211
  hash = {tracking_number: '123456', even: 2, more: 'data'}
208
212
  SemanticLogger.flush
209
213
  hash_str = hash.inspect.sub('{', '\{').sub('}', '\}')
210
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}\] LoggerTest -- Hello world -- #{hash_str}/, @mock_logger.message
214
+ assert_match(/\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}\] LoggerTest -- Hello world -- #{hash_str}/, @mock_logger.message)
211
215
  end
212
216
 
213
217
  it 'logs payload and message from block' do
@@ -215,7 +219,7 @@ class LoggerTest < Minitest::Test
215
219
  hash = {tracking_number: '123456', even: 2, more: 'data'}
216
220
  SemanticLogger.flush
217
221
  hash_str = hash.inspect.sub('{', '\{').sub('}', '\}')
218
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}\] LoggerTest -- Hello world -- #{hash_str}/, @mock_logger.message
222
+ assert_match(/\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}\] LoggerTest -- Hello world -- #{hash_str}/, @mock_logger.message)
219
223
  end
220
224
 
221
225
  it 'logs payload only' do
@@ -223,7 +227,7 @@ class LoggerTest < Minitest::Test
223
227
  @logger.send(level, hash)
224
228
  SemanticLogger.flush
225
229
  hash_str = hash.inspect.sub('{', '\{').sub('}', '\}')
226
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}\] LoggerTest -- #{hash_str}/, @mock_logger.message
230
+ assert_match(/\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}\] LoggerTest -- #{hash_str}/, @mock_logger.message)
227
231
  end
228
232
 
229
233
  it 'logs duration' do
@@ -232,12 +236,11 @@ class LoggerTest < Minitest::Test
232
236
  SemanticLogger.flush
233
237
  hash_str = hash.inspect.sub('{', '\{').sub('}', '\}')
234
238
  duration_match = defined?(JRuby) ? '\(123ms\)' : '\(123\.5ms\)'
235
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}\] #{duration_match} LoggerTest -- Hello world -- #{hash_str}/, @mock_logger.message
239
+ assert_match(/\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}\] #{duration_match} LoggerTest -- Hello world -- #{hash_str}/, @mock_logger.message)
236
240
  end
237
241
 
238
242
  it 'does not log when below min_duration' do
239
243
  @logger.send(level, min_duration: 200, duration: 123.45, message: 'Hello world', tracking_number: '123456', even: 2, more: 'data')
240
- hash = {tracking_number: '123456', even: 2, more: 'data'}
241
244
  SemanticLogger.flush
242
245
  assert_nil @mock_logger.message
243
246
  end
@@ -249,7 +252,7 @@ class LoggerTest < Minitest::Test
249
252
  SemanticLogger.flush
250
253
  hash_str = hash.inspect.sub('{', '\{').sub('}', '\}')
251
254
  duration_match = defined?(JRuby) ? '\(123ms\)' : '\(123\.5ms\)'
252
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}\] #{duration_match} LoggerTest -- Hello world -- #{hash_str}/, @mock_logger.message
255
+ assert_match(/\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}\] #{duration_match} LoggerTest -- Hello world -- #{hash_str}/, @mock_logger.message)
253
256
  assert metric_name, $last_metric.metric
254
257
  end
255
258
 
@@ -263,7 +266,7 @@ class LoggerTest < Minitest::Test
263
266
  @logger.tagged('12345', 'DJHSFK') do
264
267
  @logger.info('Hello world')
265
268
  SemanticLogger.flush
266
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ I \[\d+:#{@thread_name}\] \[12345\] \[DJHSFK\] LoggerTest -- Hello world/, @mock_logger.message
269
+ assert_match(/\d+-\d+-\d+ \d+:\d+:\d+.\d+ I \[\d+:#{@thread_name}\] \[12345\] \[DJHSFK\] LoggerTest -- Hello world/, @mock_logger.message)
267
270
  end
268
271
  end
269
272
 
@@ -272,7 +275,7 @@ class LoggerTest < Minitest::Test
272
275
  @logger.tagged('Second Level') do
273
276
  @logger.info('Hello world')
274
277
  SemanticLogger.flush
275
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ I \[\d+:#{@thread_name}\] \[First Level\] \[tags\] \[Second Level\] LoggerTest -- Hello world/, @mock_logger.message
278
+ assert_match(/\d+-\d+-\d+ \d+:\d+:\d+.\d+ I \[\d+:#{@thread_name}\] \[First Level\] \[tags\] \[Second Level\] LoggerTest -- Hello world/, @mock_logger.message)
276
279
  end
277
280
  assert_equal 2, @logger.tags.count, @logger.tags
278
281
  assert_equal 'First Level', @logger.tags.first
@@ -289,7 +292,7 @@ class LoggerTest < Minitest::Test
289
292
  @logger.with_payload(even: 2, more: 'data') do
290
293
  @logger.info('Hello world')
291
294
  SemanticLogger.flush
292
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ I \[\d+:#{@thread_name}\] LoggerTest -- Hello world -- #{hash_str}/, @mock_logger.message
295
+ assert_match(/\d+-\d+-\d+ \d+:\d+:\d+.\d+ I \[\d+:#{@thread_name}\] LoggerTest -- Hello world -- #{hash_str}/, @mock_logger.message)
293
296
  end
294
297
  end
295
298
  end
@@ -300,7 +303,7 @@ class LoggerTest < Minitest::Test
300
303
  @logger.fast_tag('12345') do
301
304
  @logger.info('Hello world')
302
305
  SemanticLogger.flush
303
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ I \[\d+:#{@thread_name}\] \[12345\] LoggerTest -- Hello world/, @mock_logger.message
306
+ assert_match(/\d+-\d+-\d+ \d+:\d+:\d+.\d+ I \[\d+:#{@thread_name}\] \[12345\] LoggerTest -- Hello world/, @mock_logger.message)
304
307
  end
305
308
  end
306
309
  end
@@ -328,13 +331,13 @@ class LoggerTest < Minitest::Test
328
331
  it "log #{level} info" do
329
332
  assert_equal 'result', @logger.send("measure_#{level}".to_sym, 'hello world') { 'result' } # Measure duration of the supplied block
330
333
  SemanticLogger.flush
331
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}\] \((\d+\.\d+)|(\d+)ms\) LoggerTest -- hello world/, @mock_logger.message
334
+ assert_match(/\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}\] \((\d+\.\d+)|(\d+)ms\) LoggerTest -- hello world/, @mock_logger.message)
332
335
  end
333
336
 
334
337
  it "log #{level} info with payload" do
335
338
  assert_equal 'result', @logger.send("measure_#{level}".to_sym, 'hello world', payload: @hash) { 'result' } # Measure duration of the supplied block
336
339
  SemanticLogger.flush
337
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}\] \((\d+\.\d+)|(\d+)ms\) LoggerTest -- hello world -- #{@hash_str}/, @mock_logger.message
340
+ assert_match(/\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}\] \((\d+\.\d+)|(\d+)ms\) LoggerTest -- hello world -- #{@hash_str}/, @mock_logger.message)
338
341
  end
339
342
 
340
343
  it "not log #{level} info when block is faster than :min_duration" do
@@ -346,7 +349,7 @@ class LoggerTest < Minitest::Test
346
349
  it "log #{level} info when block duration exceeds :min_duration" do
347
350
  assert_equal 'result', @logger.send("measure_#{level}".to_sym, 'hello world', min_duration: 200, payload: @hash) { sleep 0.5; 'result' } # Measure duration of the supplied block
348
351
  SemanticLogger.flush
349
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}\] \((\d+\.\d+)|(\d+)ms\) LoggerTest -- hello world -- #{@hash_str}/, @mock_logger.message
352
+ assert_match(/\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}\] \((\d+\.\d+)|(\d+)ms\) LoggerTest -- hello world -- #{@hash_str}/, @mock_logger.message)
350
353
  end
351
354
 
352
355
  it "log #{level} info with an exception" do
@@ -354,7 +357,7 @@ class LoggerTest < Minitest::Test
354
357
  @logger.send("measure_#{level}", 'hello world', payload: @hash) { raise RuntimeError.new("Test") } # Measure duration of the supplied block
355
358
  end
356
359
  SemanticLogger.flush
357
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}#{@file_name_reg_exp}\] \((\d+\.\d+)|(\d+)ms\) LoggerTest -- hello world -- Exception: RuntimeError: Test -- #{@hash_str}/, @mock_logger.message
360
+ assert_match(/\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}#{@file_name_reg_exp}\] \((\d+\.\d+)|(\d+)ms\) LoggerTest -- hello world -- Exception: RuntimeError: Test -- #{@hash_str}/, @mock_logger.message)
358
361
  end
359
362
 
360
363
  it "change log #{level} info with an exception" do
@@ -362,14 +365,14 @@ class LoggerTest < Minitest::Test
362
365
  @logger.send("measure_#{level}", 'hello world', payload: @hash, on_exception_level: :fatal) { raise RuntimeError.new("Test") } # Measure duration of the supplied block
363
366
  end
364
367
  SemanticLogger.flush
365
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ F \[\d+:#{@thread_name}#{@file_name_reg_exp}\] \((\d+\.\d+)|(\d+)ms\) LoggerTest -- hello world -- Exception: RuntimeError: Test -- #{@hash_str}/, @mock_logger.message
368
+ assert_match(/\d+-\d+-\d+ \d+:\d+:\d+.\d+ F \[\d+:#{@thread_name}#{@file_name_reg_exp}\] \((\d+\.\d+)|(\d+)ms\) LoggerTest -- hello world -- Exception: RuntimeError: Test -- #{@hash_str}/, @mock_logger.message)
366
369
  end
367
370
 
368
371
  it "log #{level} info with metric" do
369
372
  metric_name = '/my/custom/metric'
370
373
  assert_equal 'result', @logger.send("measure_#{level}".to_sym, 'hello world', metric: metric_name) { 'result' } # Measure duration of the supplied block
371
374
  SemanticLogger.flush
372
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}\] \((\d+\.\d+)|(\d+)ms\) LoggerTest -- hello world/, @mock_logger.message
375
+ assert_match(/\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}\] \((\d+\.\d+)|(\d+)ms\) LoggerTest -- hello world/, @mock_logger.message)
373
376
  assert metric_name, $last_metric.metric
374
377
  end
375
378
 
@@ -377,7 +380,7 @@ class LoggerTest < Minitest::Test
377
380
  SemanticLogger.stub(:backtrace_level_index, 0) do
378
381
  assert_equal 'result', @logger.send("measure_#{level}".to_sym, 'hello world') { 'result' }
379
382
  SemanticLogger.flush
380
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}#{@file_name_reg_exp}\] \((\d+\.\d+)|(\d+)ms\) LoggerTest -- hello world/, @mock_logger.message
383
+ assert_match(/\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}#{@file_name_reg_exp}\] \((\d+\.\d+)|(\d+)ms\) LoggerTest -- hello world/, @mock_logger.message)
381
384
  end
382
385
  end
383
386
  end
@@ -386,13 +389,13 @@ class LoggerTest < Minitest::Test
386
389
  it "log #{level} info" do
387
390
  assert_equal 'result', @logger.measure(level, 'hello world') { 'result' } # Measure duration of the supplied block
388
391
  SemanticLogger.flush
389
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}\] \((\d+\.\d+)|(\d+)ms\) LoggerTest -- hello world/, @mock_logger.message
392
+ assert_match(/\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}\] \((\d+\.\d+)|(\d+)ms\) LoggerTest -- hello world/, @mock_logger.message)
390
393
  end
391
394
 
392
395
  it "log #{level} info with payload" do
393
396
  assert_equal 'result', @logger.measure(level, 'hello world', payload: @hash) { 'result' } # Measure duration of the supplied block
394
397
  SemanticLogger.flush
395
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}\] \((\d+\.\d+)|(\d+)ms\) LoggerTest -- hello world -- #{@hash_str}/, @mock_logger.message
398
+ assert_match(/\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}\] \((\d+\.\d+)|(\d+)ms\) LoggerTest -- hello world -- #{@hash_str}/, @mock_logger.message)
396
399
  end
397
400
 
398
401
  it "not log #{level} info when block is faster than :min_duration" do
@@ -404,7 +407,7 @@ class LoggerTest < Minitest::Test
404
407
  it "log #{level} info when block duration exceeds :min_duration" do
405
408
  assert_equal 'result', @logger.measure(level, 'hello world', min_duration: 200, payload: @hash) { sleep 0.5; 'result' } # Measure duration of the supplied block
406
409
  SemanticLogger.flush
407
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}\] \((\d+\.\d+)|(\d+)ms\) LoggerTest -- hello world -- #{@hash_str}/, @mock_logger.message
410
+ assert_match(/\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}\] \((\d+\.\d+)|(\d+)ms\) LoggerTest -- hello world -- #{@hash_str}/, @mock_logger.message)
408
411
  end
409
412
 
410
413
  it "log #{level} info with an exception" do
@@ -412,14 +415,14 @@ class LoggerTest < Minitest::Test
412
415
  @logger.measure(level, 'hello world', payload: @hash) { raise RuntimeError.new('Test') } # Measure duration of the supplied block
413
416
  end
414
417
  SemanticLogger.flush
415
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}#{@file_name_reg_exp}\] \((\d+\.\d+)|(\d+)ms\) LoggerTest -- hello world -- Exception: RuntimeError: Test -- #{@hash_str}/, @mock_logger.message
418
+ assert_match(/\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}#{@file_name_reg_exp}\] \((\d+\.\d+)|(\d+)ms\) LoggerTest -- hello world -- Exception: RuntimeError: Test -- #{@hash_str}/, @mock_logger.message)
416
419
  end
417
420
 
418
421
  it "log #{level} info with metric" do
419
422
  metric_name = '/my/custom/metric'
420
423
  assert_equal 'result', @logger.measure(level, 'hello world', metric: metric_name) { 'result' } # Measure duration of the supplied block
421
424
  SemanticLogger.flush
422
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}\] \((\d+\.\d+)|(\d+)ms\) LoggerTest -- hello world/, @mock_logger.message
425
+ assert_match(/\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}\] \((\d+\.\d+)|(\d+)ms\) LoggerTest -- hello world/, @mock_logger.message)
423
426
  assert metric_name, $last_metric.metric
424
427
  end
425
428
 
@@ -427,7 +430,7 @@ class LoggerTest < Minitest::Test
427
430
  SemanticLogger.stub(:backtrace_level_index, 0) do
428
431
  assert_equal 'result', @logger.measure(level, 'hello world') { 'result' }
429
432
  SemanticLogger.flush
430
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}#{@file_name_reg_exp}\] \((\d+\.\d+)|(\d+)ms\) LoggerTest -- hello world/, @mock_logger.message
433
+ assert_match(/\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}#{@file_name_reg_exp}\] \((\d+\.\d+)|(\d+)ms\) LoggerTest -- hello world/, @mock_logger.message)
431
434
  end
432
435
  end
433
436
  end
@@ -436,7 +439,7 @@ class LoggerTest < Minitest::Test
436
439
  it 'log when the block performs a return' do
437
440
  assert_equal 'Good', function_with_return(@logger)
438
441
  SemanticLogger.flush
439
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ I \[\d+:#{@thread_name}\] \((\d+\.\d+)|(\d+)ms\) LoggerTest -- hello world -- #{@hash_str}/, @mock_logger.message
442
+ assert_match(/\d+-\d+-\d+ \d+:\d+:\d+.\d+ I \[\d+:#{@thread_name}\] \((\d+\.\d+)|(\d+)ms\) LoggerTest -- hello world -- #{@hash_str}/, @mock_logger.message)
440
443
  end
441
444
 
442
445
  it 'not log at a level below the silence level' do
@@ -445,7 +448,7 @@ class LoggerTest < Minitest::Test
445
448
  @logger.warn "don't log me"
446
449
  end
447
450
  SemanticLogger.flush
448
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ I \[\d+:#{@thread_name}\] \((\d+\.\d+)|(\d+)ms\) LoggerTest -- hello world/, @mock_logger.message
451
+ assert_match(/\d+-\d+-\d+ \d+:\d+:\d+.\d+ I \[\d+:#{@thread_name}\] \((\d+\.\d+)|(\d+)ms\) LoggerTest -- hello world/, @mock_logger.message)
449
452
  end
450
453
 
451
454
  it 'log at a silence level below the default level' do
@@ -456,10 +459,10 @@ class LoggerTest < Minitest::Test
456
459
  SemanticLogger.flush
457
460
  first_message = @mock_logger.message
458
461
  end
459
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ D \[\d+:#{@thread_name}\] LoggerTest -- hello world -- Calculations -- #{@hash_str}/, first_message
462
+ assert_match(/\d+-\d+-\d+ \d+:\d+:\d+.\d+ D \[\d+:#{@thread_name}\] LoggerTest -- hello world -- Calculations -- #{@hash_str}/, first_message)
460
463
  SemanticLogger.flush
461
464
  # Only the last log message is kept in mock logger
462
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ I \[\d+:#{@thread_name}\] \((\d+\.\d+)|(\d+)ms\) LoggerTest -- hello world/, @mock_logger.message
465
+ assert_match(/\d+-\d+-\d+ \d+:\d+:\d+.\d+ I \[\d+:#{@thread_name}\] \((\d+\.\d+)|(\d+)ms\) LoggerTest -- hello world/, @mock_logger.message)
463
466
  end
464
467
  end
465
468
 
@@ -482,7 +485,7 @@ class LoggerTest < Minitest::Test
482
485
  assert_equal :trace, @logger.level
483
486
  @logger.trace('hello world', @hash) { 'Calculations' }
484
487
  SemanticLogger.flush
485
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ T \[\d+:#{@thread_name}\] LoggerTest -- hello world -- Calculations -- #{@hash_str}/, @mock_logger.message
488
+ assert_match(/\d+-\d+-\d+ \d+:\d+:\d+.\d+ T \[\d+:#{@thread_name}\] LoggerTest -- hello world -- Calculations -- #{@hash_str}/, @mock_logger.message)
486
489
  end
487
490
 
488
491
  it 'not log at a level below the instance level' do
@@ -520,7 +523,7 @@ class LoggerTest < Minitest::Test
520
523
  @logger.trace('hello world', @hash) { 'Calculations' }
521
524
  end
522
525
  SemanticLogger.flush
523
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ T \[\d+:#{@thread_name}\] LoggerTest -- hello world -- Calculations -- #{@hash_str}/, @mock_logger.message
526
+ assert_match(/\d+-\d+-\d+ \d+:\d+:\d+.\d+ T \[\d+:#{@thread_name}\] LoggerTest -- hello world -- Calculations -- #{@hash_str}/, @mock_logger.message)
524
527
  end
525
528
 
526
529
  it 'log at a silence level below the default level' do
@@ -530,7 +533,7 @@ class LoggerTest < Minitest::Test
530
533
  @logger.debug('hello world', @hash) { 'Calculations' }
531
534
  end
532
535
  SemanticLogger.flush
533
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ D \[\d+:#{@thread_name}\] LoggerTest -- hello world -- Calculations -- #{@hash_str}/, @mock_logger.message
536
+ assert_match(/\d+-\d+-\d+ \d+:\d+:\d+.\d+ D \[\d+:#{@thread_name}\] LoggerTest -- hello world -- Calculations -- #{@hash_str}/, @mock_logger.message)
534
537
  end
535
538
  end
536
539
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: semantic_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.1
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Reid Morrison
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-08 00:00:00.000000000 Z
11
+ date: 2016-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -37,7 +37,6 @@ files:
37
37
  - Rakefile
38
38
  - lib/semantic_logger.rb
39
39
  - lib/semantic_logger/ansi_colors.rb
40
- - lib/semantic_logger/appender/base.rb
41
40
  - lib/semantic_logger/appender/bugsnag.rb
42
41
  - lib/semantic_logger/appender/elasticsearch.rb
43
42
  - lib/semantic_logger/appender/file.rb
@@ -49,21 +48,28 @@ files:
49
48
  - lib/semantic_logger/appender/splunk.rb
50
49
  - lib/semantic_logger/appender/splunk_http.rb
51
50
  - lib/semantic_logger/appender/syslog.rb
51
+ - lib/semantic_logger/appender/tcp.rb
52
+ - lib/semantic_logger/appender/udp.rb
52
53
  - lib/semantic_logger/appender/wrapper.rb
53
54
  - lib/semantic_logger/base.rb
54
55
  - lib/semantic_logger/concerns/compatibility.rb
55
56
  - lib/semantic_logger/core_ext/thread.rb
56
57
  - lib/semantic_logger/debug_as_trace_logger.rb
58
+ - lib/semantic_logger/formatters/base.rb
57
59
  - lib/semantic_logger/formatters/color.rb
58
60
  - lib/semantic_logger/formatters/default.rb
59
61
  - lib/semantic_logger/formatters/json.rb
62
+ - lib/semantic_logger/formatters/raw.rb
63
+ - lib/semantic_logger/formatters/syslog.rb
60
64
  - lib/semantic_logger/jruby/garbage_collection_logger.rb
61
65
  - lib/semantic_logger/log.rb
62
66
  - lib/semantic_logger/loggable.rb
63
67
  - lib/semantic_logger/logger.rb
64
68
  - lib/semantic_logger/metrics/new_relic.rb
65
69
  - lib/semantic_logger/metrics/statsd.rb
70
+ - lib/semantic_logger/metrics/udp.rb
66
71
  - lib/semantic_logger/semantic_logger.rb
72
+ - lib/semantic_logger/subscriber.rb
67
73
  - lib/semantic_logger/version.rb
68
74
  - test/appender/bugsnag_test.rb
69
75
  - test/appender/elasticsearch_test.rb
@@ -77,6 +83,8 @@ files:
77
83
  - test/appender/splunk_http_test.rb
78
84
  - test/appender/splunk_test.rb
79
85
  - test/appender/syslog_test.rb
86
+ - test/appender/tcp_test.rb
87
+ - test/appender/udp_test.rb
80
88
  - test/appender/wrapper_test.rb
81
89
  - test/concerns/compatibility_test.rb
82
90
  - test/debug_as_trace_logger_test.rb
@@ -121,6 +129,8 @@ test_files:
121
129
  - test/appender/splunk_http_test.rb
122
130
  - test/appender/splunk_test.rb
123
131
  - test/appender/syslog_test.rb
132
+ - test/appender/tcp_test.rb
133
+ - test/appender/udp_test.rb
124
134
  - test/appender/wrapper_test.rb
125
135
  - test/concerns/compatibility_test.rb
126
136
  - test/debug_as_trace_logger_test.rb
@@ -1,101 +0,0 @@
1
- # Base appender
2
- #
3
- # Abstract base class for appenders
4
- #
5
- # Implements common behavior such as default text formatter etc
6
- #
7
- # Note: Do not create instances of this class directly
8
- #
9
- module SemanticLogger
10
- module Appender
11
-
12
- # DEPRECATED, use SemanticLogger::AnsiColors
13
- AnsiColors = SemanticLogger::AnsiColors
14
-
15
- class Base < SemanticLogger::Base
16
- # Every logger has its own formatter
17
- attr_accessor :formatter
18
-
19
- # Returns the current log level if set, otherwise it logs everything it receives
20
- def level
21
- @level || :trace
22
- end
23
-
24
- # An appender can implement a flush method if it is able to.
25
- def flush
26
- # NOOP
27
- end
28
-
29
- # DEPRECATED: use SemanticLogger::Formatters::Default.new
30
- def default_formatter
31
- warn '[DEPRECATION] SemanticLogger::Appender::Base.default_level is deprecated. Please use SemanticLogger::Formatters::Default.new instead.'
32
- formatter = SemanticLogger::Formatters::Default.new
33
- Proc.new { |log, logger| formatter.call(log, logger) }
34
- end
35
-
36
- # DEPRECATED: use SemanticLogger::Formatters::Color.new
37
- def self.colorized_formatter
38
- warn '[DEPRECATION] SemanticLogger::Appender::Base.colorized_formatter is deprecated. Please use SemanticLogger::Formatters::Color.new instead.'
39
- formatter = SemanticLogger::Formatters::Color.new
40
- Proc.new { |log, logger| formatter.call(log, logger) }
41
- end
42
-
43
- # DEPRECATED: use SemanticLogger::Formatters::Json.new
44
- def self.json_formatter
45
- warn '[DEPRECATION] SemanticLogger::Appender::Base.json_formatter is deprecated. Please use SemanticLogger::Formatters::Json.new instead.'
46
- formatter = SemanticLogger::Formatters::Json.new
47
- Proc.new { |log, logger| formatter.call(log, logger) }
48
- end
49
-
50
- private
51
-
52
- # Initializer for Abstract Class SemanticLogger::Appender
53
- #
54
- # Parameters
55
- # level: [:trace | :debug | :info | :warn | :error | :fatal]
56
- # Override the log level for this appender.
57
- # Default: :error
58
- #
59
- # formatter: [Object|Proc]
60
- # An instance of a class that implements #call, or a Proc to be used to format
61
- # the output from this appender
62
- # Default: Use the built-in formatter (See: #call)
63
- #
64
- # filter: [Regexp|Proc]
65
- # RegExp: Only include log messages where the class name matches the supplied.
66
- # regular expression. All other messages will be ignored.
67
- # Proc: Only include log messages where the supplied Proc returns true
68
- # The Proc must return true or false.
69
- def initialize(options={}, &block)
70
- # Backward compatibility
71
- options = {level: options} unless options.is_a?(Hash)
72
- options = options.dup
73
- level = options.delete(:level)
74
- filter = options.delete(:filter)
75
- @formatter = options.delete(:formatter)
76
- @formatter = self.class.extract_formatter(@formatter) if @formatter.is_a?(Symbol)
77
- @formatter ||= block
78
- # Default to #call method for formatting if defined for an appender
79
- @formatter ||= (respond_to?(:call) ? self : SemanticLogger::Formatters::Default.new)
80
- raise(ArgumentError, "Unknown options: #{options.inspect}") if options.size > 0
81
-
82
- # Appenders don't take a class name, so use this class name if an appender
83
- # is logged to directly
84
- super(self.class, level, filter)
85
- end
86
-
87
- # Return the level index for fast comparisons
88
- # Returns the lowest level index if the level has not been explicitly
89
- # set for this instance
90
- def level_index
91
- @level_index || 0
92
- end
93
-
94
- # Return formatter for supplied Symbol
95
- def self.extract_formatter(formatter)
96
- SemanticLogger.send(:named_formatter, formatter).new
97
- end
98
-
99
- end
100
- end
101
- end