semantic_logger 4.2.0 → 4.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -3
  3. data/Rakefile +1 -1
  4. data/lib/semantic_logger/ansi_colors.rb +11 -12
  5. data/lib/semantic_logger/appender.rb +4 -5
  6. data/lib/semantic_logger/appender/async.rb +24 -16
  7. data/lib/semantic_logger/appender/async_batch.rb +1 -4
  8. data/lib/semantic_logger/appender/bugsnag.rb +67 -63
  9. data/lib/semantic_logger/appender/elasticsearch.rb +154 -157
  10. data/lib/semantic_logger/appender/elasticsearch_http.rb +59 -55
  11. data/lib/semantic_logger/appender/file.rb +1 -3
  12. data/lib/semantic_logger/appender/graylog.rb +114 -110
  13. data/lib/semantic_logger/appender/honeybadger.rb +54 -51
  14. data/lib/semantic_logger/appender/http.rb +194 -190
  15. data/lib/semantic_logger/appender/kafka.rb +152 -149
  16. data/lib/semantic_logger/appender/mongodb.rb +3 -3
  17. data/lib/semantic_logger/appender/new_relic.rb +52 -49
  18. data/lib/semantic_logger/appender/sentry.rb +59 -54
  19. data/lib/semantic_logger/appender/splunk.rb +108 -103
  20. data/lib/semantic_logger/appender/splunk_http.rb +82 -79
  21. data/lib/semantic_logger/appender/syslog.rb +4 -5
  22. data/lib/semantic_logger/appender/tcp.rb +8 -29
  23. data/lib/semantic_logger/appender/udp.rb +2 -3
  24. data/lib/semantic_logger/appender/wrapper.rb +2 -2
  25. data/lib/semantic_logger/base.rb +18 -16
  26. data/lib/semantic_logger/concerns/compatibility.rb +0 -1
  27. data/lib/semantic_logger/core_ext/thread.rb +0 -1
  28. data/lib/semantic_logger/formatters.rb +3 -5
  29. data/lib/semantic_logger/formatters/base.rb +2 -3
  30. data/lib/semantic_logger/formatters/color.rb +29 -12
  31. data/lib/semantic_logger/formatters/default.rb +10 -10
  32. data/lib/semantic_logger/formatters/json.rb +0 -2
  33. data/lib/semantic_logger/formatters/one_line.rb +2 -2
  34. data/lib/semantic_logger/formatters/raw.rb +7 -10
  35. data/lib/semantic_logger/formatters/signalfx.rb +3 -5
  36. data/lib/semantic_logger/formatters/syslog.rb +2 -3
  37. data/lib/semantic_logger/formatters/syslog_cee.rb +2 -3
  38. data/lib/semantic_logger/jruby/garbage_collection_logger.rb +8 -5
  39. data/lib/semantic_logger/log.rb +17 -17
  40. data/lib/semantic_logger/loggable.rb +6 -9
  41. data/lib/semantic_logger/logger.rb +0 -1
  42. data/lib/semantic_logger/metric/new_relic.rb +58 -55
  43. data/lib/semantic_logger/metric/signalfx.rb +108 -106
  44. data/lib/semantic_logger/metric/statsd.rb +2 -3
  45. data/lib/semantic_logger/processor.rb +9 -9
  46. data/lib/semantic_logger/semantic_logger.rb +50 -30
  47. data/lib/semantic_logger/subscriber.rb +0 -1
  48. data/lib/semantic_logger/utils.rb +37 -37
  49. data/lib/semantic_logger/version.rb +2 -2
  50. data/test/appender/async_batch_test.rb +0 -1
  51. data/test/appender/async_test.rb +0 -1
  52. data/test/appender/bugsnag_test.rb +7 -8
  53. data/test/appender/elasticsearch_http_test.rb +5 -6
  54. data/test/appender/elasticsearch_test.rb +14 -10
  55. data/test/appender/file_test.rb +5 -6
  56. data/test/appender/graylog_test.rb +8 -8
  57. data/test/appender/honeybadger_test.rb +6 -7
  58. data/test/appender/http_test.rb +4 -5
  59. data/test/appender/kafka_test.rb +5 -6
  60. data/test/appender/mongodb_test.rb +11 -13
  61. data/test/appender/new_relic_test.rb +8 -9
  62. data/test/appender/newrelic_rpm.rb +1 -1
  63. data/test/appender/sentry_test.rb +7 -8
  64. data/test/appender/splunk_http_test.rb +4 -4
  65. data/test/appender/splunk_test.rb +1 -3
  66. data/test/appender/syslog_test.rb +3 -5
  67. data/test/appender/tcp_test.rb +4 -5
  68. data/test/appender/udp_test.rb +4 -5
  69. data/test/appender/wrapper_test.rb +2 -3
  70. data/test/concerns/compatibility_test.rb +0 -1
  71. data/test/debug_as_trace_logger_test.rb +0 -1
  72. data/test/formatters/color_test.rb +5 -6
  73. data/test/formatters/default_test.rb +16 -17
  74. data/test/formatters/one_line_test.rb +1 -2
  75. data/test/formatters/signalfx_test.rb +8 -11
  76. data/test/formatters_test.rb +3 -3
  77. data/test/in_memory_appender.rb +0 -1
  78. data/test/in_memory_appender_helper.rb +1 -1
  79. data/test/in_memory_batch_appender.rb +0 -1
  80. data/test/in_memory_metrics_appender.rb +0 -1
  81. data/test/loggable_test.rb +2 -3
  82. data/test/logger_test.rb +11 -14
  83. data/test/measure_test.rb +13 -15
  84. data/test/metric/new_relic_test.rb +2 -3
  85. data/test/metric/signalfx_test.rb +4 -5
  86. data/test/semantic_logger_test.rb +28 -3
  87. data/test/test_helper.rb +6 -7
  88. metadata +34 -34
@@ -3,7 +3,7 @@ require 'socket'
3
3
 
4
4
  module SemanticLogger
5
5
  # Logging levels in order of most detailed to most severe
6
- LEVELS = [:trace, :debug, :info, :warn, :error, :fatal]
6
+ LEVELS = %i[trace debug info warn error fatal].freeze
7
7
 
8
8
  # Return a logger for the supplied class or class_name
9
9
  def self.[](klass)
@@ -35,7 +35,7 @@ module SemanticLogger
35
35
  def self.backtrace_level=(level)
36
36
  @backtrace_level = level
37
37
  # For performance reasons pre-calculate the level index
38
- @backtrace_level_index = level.nil? ? 65535 : level_to_index(level)
38
+ @backtrace_level_index = level.nil? ? 65_535 : level_to_index(level)
39
39
  end
40
40
 
41
41
  # Returns the current backtrace level
@@ -45,14 +45,14 @@ module SemanticLogger
45
45
 
46
46
  # Returns the current backtrace level index
47
47
  # For internal use only
48
- def self.backtrace_level_index #:nodoc
48
+ def self.backtrace_level_index
49
49
  @backtrace_level_index
50
50
  end
51
51
 
52
52
  # Returns [String] name of this host for logging purposes
53
53
  # Note: Not all appenders use `host`
54
54
  def self.host
55
- @host ||= Socket.gethostname.force_encoding("UTF-8")
55
+ @host ||= Socket.gethostname.force_encoding('UTF-8')
56
56
  end
57
57
 
58
58
  # Override the default host name
@@ -223,7 +223,7 @@ module SemanticLogger
223
223
  # * This callback is called within the thread of the application making the logging call.
224
224
  # * If these callbacks are slow they will slow down the application.
225
225
  def self.on_log(object = nil, &block)
226
- Processor.instance.on_log(object, &block)
226
+ Processor.instance.appender.on_log(object, &block)
227
227
  end
228
228
 
229
229
  # Add signal handlers for Semantic Logger
@@ -261,22 +261,26 @@ module SemanticLogger
261
261
  # Note:
262
262
  # To only register one of the signal handlers, set the other to nil
263
263
  # Set gc_log_microseconds to nil to not enable JRuby Garbage collections
264
- def self.add_signal_handler(log_level_signal='USR2', thread_dump_signal='TTIN', gc_log_microseconds=100000)
265
- Signal.trap(log_level_signal) do
266
- index = (default_level == :trace) ? LEVELS.find_index(:error) : LEVELS.find_index(default_level)
267
- new_level = LEVELS[index-1]
268
- self['SemanticLogger'].warn "Changed global default log level to #{new_level.inspect}"
269
- self.default_level = new_level
270
- end if log_level_signal
271
-
272
- Signal.trap(thread_dump_signal) do
273
- logger = SemanticLogger['Thread Dump']
274
- Thread.list.each do |thread|
275
- # MRI re-uses the main thread for signals, JRuby uses `SIGTTIN handler` thread.
276
- next if defined?(JRuby) && (thread == Thread.current)
277
- logger.backtrace(thread: thread)
264
+ def self.add_signal_handler(log_level_signal = 'USR2', thread_dump_signal = 'TTIN', gc_log_microseconds = 100_000)
265
+ if log_level_signal
266
+ Signal.trap(log_level_signal) do
267
+ index = default_level == :trace ? LEVELS.find_index(:error) : LEVELS.find_index(default_level)
268
+ new_level = LEVELS[index - 1]
269
+ self['SemanticLogger'].warn "Changed global default log level to #{new_level.inspect}"
270
+ self.default_level = new_level
278
271
  end
279
- end if thread_dump_signal
272
+ end
273
+
274
+ if thread_dump_signal
275
+ Signal.trap(thread_dump_signal) do
276
+ logger = SemanticLogger['Thread Dump']
277
+ Thread.list.each do |thread|
278
+ # MRI re-uses the main thread for signals, JRuby uses `SIGTTIN handler` thread.
279
+ next if defined?(JRuby) && (thread == Thread.current)
280
+ logger.backtrace(thread: thread)
281
+ end
282
+ end
283
+ end
280
284
 
281
285
  if gc_log_microseconds && defined?(JRuby)
282
286
  listener = SemanticLogger::JRuby::GarbageCollectionLogger.new(gc_log_microseconds)
@@ -360,9 +364,9 @@ module SemanticLogger
360
364
  end
361
365
 
362
366
  # Remove specified number of tags from the current tag list
363
- def self.pop_tags(quantity=1)
367
+ def self.pop_tags(quantity = 1)
364
368
  t = Thread.current[:semantic_logger_tags]
365
- t.pop(quantity) unless t.nil?
369
+ t&.pop(quantity)
366
370
  end
367
371
 
368
372
  # :nodoc
@@ -370,12 +374,11 @@ module SemanticLogger
370
374
  return yield if hash.nil? || hash.empty?
371
375
  raise(ArgumentError, '#named_tagged only accepts named parameters (Hash)') unless hash.is_a?(Hash)
372
376
 
373
- t = Thread.current[:semantic_logger_named_tags] ||= []
374
377
  begin
375
- t << hash
378
+ push_named_tags(hash)
376
379
  yield
377
380
  ensure
378
- t.pop
381
+ pop_named_tags
379
382
  end
380
383
  end
381
384
 
@@ -392,6 +395,16 @@ module SemanticLogger
392
395
  end
393
396
  end
394
397
 
398
+ def self.push_named_tags(hash)
399
+ (Thread.current[:semantic_logger_named_tags] ||= []) << hash
400
+ hash
401
+ end
402
+
403
+ def self.pop_named_tags(quantity = 1)
404
+ t = Thread.current[:semantic_logger_named_tags]
405
+ t&.pop(quantity)
406
+ end
407
+
395
408
  # Silence noisy log levels by changing the default_level within the block
396
409
  #
397
410
  # This setting is thread-safe and only applies to the current thread
@@ -436,19 +449,19 @@ module SemanticLogger
436
449
  Thread.current[:semantic_logger_silence] = current_index
437
450
  end
438
451
 
439
- private
440
-
441
- @appenders = Concurrent::Array.new
442
-
443
452
  def self.default_level_index
444
453
  Thread.current[:semantic_logger_silence] || @default_level_index
445
454
  end
446
455
 
456
+ # private_class_method :default_level_index
457
+
447
458
  # Returns the symbolic level for the supplied level index
448
459
  def self.index_to_level(level_index)
449
460
  LEVELS[level_index]
450
461
  end
451
462
 
463
+ # private_class_method :index_to_level
464
+
452
465
  # Internal method to return the log level as an internal index
453
466
  # Also supports mapping the ::Logger levels to SemanticLogger levels
454
467
  def self.level_to_index(level)
@@ -465,7 +478,8 @@ module SemanticLogger
465
478
  @map_levels ||= begin
466
479
  levels = []
467
480
  ::Logger::Severity.constants.each do |constant|
468
- levels[::Logger::Severity.const_get(constant)] = LEVELS.find_index(constant.downcase.to_sym) || LEVELS.find_index(:error)
481
+ levels[::Logger::Severity.const_get(constant)] =
482
+ LEVELS.find_index(constant.downcase.to_sym) || LEVELS.find_index(:error)
469
483
  end
470
484
  levels
471
485
  end
@@ -475,6 +489,8 @@ module SemanticLogger
475
489
  index
476
490
  end
477
491
 
492
+ # private_class_method :level_to_index
493
+
478
494
  # Backward compatibility
479
495
  def self.convert_old_appender_args(appender, level)
480
496
  options = {}
@@ -493,6 +509,10 @@ module SemanticLogger
493
509
  options
494
510
  end
495
511
 
512
+ private_class_method :convert_old_appender_args
513
+
514
+ @appenders = Concurrent::Array.new
515
+
496
516
  # Initial default Level for all new instances of SemanticLogger::Logger
497
517
  @default_level = :info
498
518
  @default_level_index = level_to_index(@default_level)
@@ -104,6 +104,5 @@ module SemanticLogger
104
104
  def level_index
105
105
  @level_index || 0
106
106
  end
107
-
108
107
  end
109
108
  end
@@ -1,47 +1,47 @@
1
- module SemanticLogger::Utils
2
-
3
- def self.constantize_symbol(symbol, namespace = 'SemanticLogger::Appender')
4
- klass = "#{namespace}::#{camelize(symbol.to_s)}"
5
- begin
6
- if RUBY_VERSION.to_i >= 2
7
- Object.const_get(klass)
8
- else
9
- klass.split('::').inject(Object) { |o, name| o.const_get(name) }
1
+ module SemanticLogger
2
+ module Utils
3
+ def self.constantize_symbol(symbol, namespace = 'SemanticLogger::Appender')
4
+ klass = "#{namespace}::#{camelize(symbol.to_s)}"
5
+ begin
6
+ if RUBY_VERSION.to_i >= 2
7
+ Object.const_get(klass)
8
+ else
9
+ klass.split('::').inject(Object) { |o, name| o.const_get(name) }
10
+ end
11
+ rescue NameError
12
+ raise(ArgumentError, "Could not convert symbol: #{symbol.inspect} to a class in: #{namespace}. Looking for: #{klass}")
10
13
  end
11
- rescue NameError
12
- raise(ArgumentError, "Could not convert symbol: #{symbol.inspect} to a class in: #{namespace}. Looking for: #{klass}")
13
14
  end
14
- end
15
15
 
16
- # Borrow from Rails, when not running Rails
17
- def self.camelize(term)
18
- string = term.to_s
19
- string = string.sub(/^[a-z\d]*/) { |match| match.capitalize }
20
- string.gsub!(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{$2.capitalize}" }
21
- string.gsub!('/'.freeze, '::'.freeze)
22
- string
23
- end
16
+ # Borrow from Rails, when not running Rails
17
+ def self.camelize(term)
18
+ string = term.to_s
19
+ string = string.sub(/^[a-z\d]*/, &:capitalize)
20
+ string.gsub!(/(?:_|(\/))([a-z\d]*)/i) { "#{Regexp.last_match(1)}#{Regexp.last_match(2).capitalize}" }
21
+ string.gsub!('/'.freeze, '::'.freeze)
22
+ string
23
+ end
24
24
 
25
- # Returns the visibility for an instance method
26
- def self.method_visibility(mod, method_name)
27
- method_name = method_name.to_sym
28
- if mod.instance_methods.include?(method_name)
29
- :public
30
- elsif mod.private_instance_methods.include?(method_name)
31
- :private
32
- elsif mod.protected_instance_methods.include?(method_name)
33
- :protected
25
+ # Returns the visibility for an instance method
26
+ def self.method_visibility(mod, method_name)
27
+ method_name = method_name.to_sym
28
+ if mod.instance_methods.include?(method_name)
29
+ :public
30
+ elsif mod.private_instance_methods.include?(method_name)
31
+ :private
32
+ elsif mod.protected_instance_methods.include?(method_name)
33
+ :protected
34
+ end
34
35
  end
35
- end
36
36
 
37
- SELF_PATTERN = File.join('lib', 'semantic_logger')
37
+ SELF_PATTERN = File.join('lib', 'semantic_logger')
38
38
 
39
- # Extract the backtrace leaving out the last few Semantic Logger lines.
40
- def self.cleanse_backtrace(stack = caller)
41
- while (first = stack.first) && first.include?(SELF_PATTERN)
42
- stack.shift
39
+ # Extract the backtrace leaving out the last few Semantic Logger lines.
40
+ def self.cleanse_backtrace(stack = caller)
41
+ while (first = stack.first) && first.include?(SELF_PATTERN)
42
+ stack.shift
43
+ end
44
+ stack
43
45
  end
44
- stack
45
46
  end
46
-
47
47
  end
@@ -1,3 +1,3 @@
1
- module SemanticLogger #:nodoc
2
- VERSION = '4.2.0'
1
+ module SemanticLogger
2
+ VERSION = '4.2.1'.freeze
3
3
  end
@@ -55,7 +55,6 @@ module Appender
55
55
  assert_equal 'hello world', logs.first.message
56
56
  end
57
57
  end
58
-
59
58
  end
60
59
  end
61
60
  end
@@ -39,7 +39,6 @@ module Appender
39
39
  assert_instance_of Queue, added_appender.queue
40
40
  end
41
41
  end
42
-
43
42
  end
44
43
  end
45
44
  end
@@ -21,10 +21,10 @@ module Appender
21
21
  level.to_s
22
22
  end
23
23
  exception = hash = nil
24
- Bugsnag.stub(:notify, -> exc, h { exception = exc; hash = h }) do
24
+ Bugsnag.stub(:notify, ->(exc, h) { exception = exc; hash = h }) do
25
25
  @appender.send(level, @message)
26
26
  end
27
- if [:trace, :debug].include?(level)
27
+ if %i[trace debug].include?(level)
28
28
  assert_nil exception
29
29
  assert_nil hash
30
30
  else
@@ -36,10 +36,10 @@ module Appender
36
36
 
37
37
  it "sends #{level} custom attributes" do
38
38
  exception = hash = nil
39
- Bugsnag.stub(:notify, -> exc, h { exception = exc; hash = h }) do
40
- @appender.send(level, @message, {key1: 1, key2: 'a'})
39
+ Bugsnag.stub(:notify, ->(exc, h) { exception = exc; hash = h }) do
40
+ @appender.send(level, @message, key1: 1, key2: 'a')
41
41
  end
42
- if [:trace, :debug].include?(level)
42
+ if %i[trace debug].include?(level)
43
43
  assert_nil exception
44
44
  assert_nil hash
45
45
  else
@@ -54,10 +54,10 @@ module Appender
54
54
  it "sends #{level} exceptions" do
55
55
  error = RuntimeError.new('Hello World')
56
56
  exception = hash = nil
57
- Bugsnag.stub(:notify, -> exc, h { exception = exc; hash = h }) do
57
+ Bugsnag.stub(:notify, ->(exc, h) { exception = exc; hash = h }) do
58
58
  @appender.send(level, @message, error)
59
59
  end
60
- if [:trace, :debug].include?(level)
60
+ if %i[trace debug].include?(level)
61
61
  assert_nil exception
62
62
  assert_nil hash
63
63
  else
@@ -67,7 +67,6 @@ module Appender
67
67
  end
68
68
  end
69
69
  end
70
-
71
70
  end
72
71
  end
73
72
  end
@@ -17,7 +17,7 @@ module Appender
17
17
 
18
18
  it 'logs to daily indexes' do
19
19
  index = nil
20
- @appender.stub(:post, -> json, ind { index = ind }) do
20
+ @appender.stub(:post, ->(_json, ind) { index = ind }) do
21
21
  @appender.info @message
22
22
  end
23
23
  assert_equal "/semantic_logger-#{Time.now.utc.strftime('%Y.%m.%d')}/log", index
@@ -26,7 +26,7 @@ module Appender
26
26
  SemanticLogger::LEVELS.each do |level|
27
27
  it "send #{level}" do
28
28
  request = nil
29
- @appender.http.stub(:request, -> r { request = r; response_mock.new('200', 'ok') }) do
29
+ @appender.http.stub(:request, ->(r) { request = r; response_mock.new('200', 'ok') }) do
30
30
  @appender.send(level, @message)
31
31
  end
32
32
  message = JSON.parse(request.body)
@@ -43,7 +43,7 @@ module Appender
43
43
  exc = e
44
44
  end
45
45
  request = nil
46
- @appender.http.stub(:request, -> r { request = r; response_mock.new('200', 'ok') }) do
46
+ @appender.http.stub(:request, ->(r) { request = r; response_mock.new('200', 'ok') }) do
47
47
  @appender.send(level, 'Reading File', exc)
48
48
  end
49
49
  hash = JSON.parse(request.body)
@@ -57,8 +57,8 @@ module Appender
57
57
 
58
58
  it "sends #{level} custom attributes" do
59
59
  request = nil
60
- @appender.http.stub(:request, -> r { request = r; response_mock.new('200', 'ok') }) do
61
- @appender.send(level, @message, {key1: 1, key2: 'a'})
60
+ @appender.http.stub(:request, ->(r) { request = r; response_mock.new('200', 'ok') }) do
61
+ @appender.send(level, @message, key1: 1, key2: 'a')
62
62
  end
63
63
  message = JSON.parse(request.body)
64
64
  assert_equal @message, message['message']
@@ -69,7 +69,6 @@ module Appender
69
69
  assert_equal 'a', payload['key2'], message
70
70
  end
71
71
  end
72
-
73
72
  end
74
73
  end
75
74
  end
@@ -106,13 +106,15 @@ module Appender
106
106
  request = stub_client { appender.batch(logs) }
107
107
 
108
108
  assert body = request[:body]
109
- assert_equal 4, body.size, body
110
- index = body[0]['index']['_index']
111
- assert_equal "semantic_logger-#{Time.now.strftime('%Y.%m.%d')}", index
109
+ assert_equal 6, body.size, body
112
110
 
111
+ index = "semantic_logger-#{Time.now.strftime('%Y.%m.%d')}"
112
+ assert_equal index, body[0]['index']['_index']
113
113
  assert_equal 'hello world1', body[1][:message]
114
- assert_equal 'hello world2', body[2][:message]
115
- assert_equal 'hello world3', body[3][:message]
114
+ assert_equal index, body[2]['index']['_index']
115
+ assert_equal 'hello world2', body[3][:message]
116
+ assert_equal index, body[4]['index']['_index']
117
+ assert_equal 'hello world3', body[5][:message]
116
118
  end
117
119
  end
118
120
 
@@ -223,13 +225,15 @@ module Appender
223
225
  request = stub_client { appender.batch(logs) }
224
226
 
225
227
  assert body = request[:body]
226
- assert_equal 4, body.size, body
227
- index = body[0]['index']['_index']
228
- assert_equal "semantic_logger-#{Time.now.strftime('%Y.%m.%d')}", index
228
+ assert_equal 6, body.size, body
229
229
 
230
+ index = "semantic_logger-#{Time.now.strftime('%Y.%m.%d')}"
231
+ assert_equal index, body[0]['index']['_index']
230
232
  assert_equal 'hello world1', body[1][:message]
231
- assert_equal 'hello world2', body[2][:message]
232
- assert_equal 'hello world3', body[3][:message]
233
+ assert_equal index, body[2]['index']['_index']
234
+ assert_equal 'hello world2', body[3][:message]
235
+ assert_equal index, body[4]['index']['_index']
236
+ assert_equal 'hello world3', body[5][:message]
233
237
  end
234
238
  end
235
239
 
@@ -12,8 +12,8 @@ module Appender
12
12
  @time = Time.new
13
13
  @io = StringIO.new
14
14
  @appender = SemanticLogger::Appender::File.new(io: @io)
15
- @hash = {session_id: 'HSSKLEU@JDK767', tracking_number: 12345}
16
- @hash_str = @hash.inspect.sub("{", "\\{").sub("}", "\\}")
15
+ @hash = {session_id: 'HSSKLEU@JDK767', tracking_number: 12_345}
16
+ @hash_str = @hash.inspect.sub('{', '\\{').sub('}', '\\}')
17
17
  @thread_name = Thread.current.name
18
18
  @file_name_reg_exp = RUBY_VERSION.to_f <= 2.0 ? ' (mock|file_test).rb:\d+' : ' file_test.rb:\d+'
19
19
  end
@@ -88,15 +88,15 @@ module Appender
88
88
  describe 'custom formatter' do
89
89
  before do
90
90
  @appender = SemanticLogger::Appender::File.new(io: @io) do |log|
91
- tags = log.tags.collect { |tag| "[#{tag}]" }.join(' ') + ' ' if log.tags && (log.tags.size > 0)
91
+ tags = log.tags.collect { |tag| "[#{tag}]" }.join(' ') + ' ' if log.tags&.size&.positive?
92
92
 
93
93
  message = log.message.to_s
94
94
  message << ' -- ' << log.payload.inspect if log.payload
95
95
  message << ' -- ' << "#{log.exception.class}: #{log.exception.message}\n#{(log.exception.backtrace || []).join("\n")}" if log.exception
96
96
 
97
- duration_str = log.duration ? " (#{'%.1f' % log.duration}ms)" : ''
97
+ duration_str = log.duration ? " (#{format('%.1f', log.duration)}ms)" : ''
98
98
 
99
- "#{log.formatted_time} #{log.level.to_s.upcase} [#{$$}:#{log.thread_name}] #{tags}#{log.name} -- #{message}#{duration_str}"
99
+ "#{log.formatted_time} #{log.level.to_s.upcase} [#{$PROCESS_ID}:#{log.thread_name}] #{tags}#{log.name} -- #{message}#{duration_str}"
100
100
  end
101
101
  end
102
102
 
@@ -105,7 +105,6 @@ module Appender
105
105
  assert_match(/\d+-\d+-\d+ \d+:\d+:\d+.\d+ DEBUG \[\d+:#{@thread_name}\] SemanticLogger::Appender::File -- \n/, @io.string)
106
106
  end
107
107
  end
108
-
109
108
  end
110
109
  end
111
110
  end