semantic_logger 4.3.1 → 4.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/lib/semantic_logger.rb +7 -1
  3. data/lib/semantic_logger/appender.rb +3 -0
  4. data/lib/semantic_logger/appender/async.rb +29 -10
  5. data/lib/semantic_logger/appender/rabbitmq.rb +120 -0
  6. data/lib/semantic_logger/appenders.rb +89 -0
  7. data/lib/semantic_logger/base.rb +3 -3
  8. data/lib/semantic_logger/concerns/compatibility.rb +2 -2
  9. data/lib/semantic_logger/formatters.rb +1 -0
  10. data/lib/semantic_logger/formatters/base.rb +28 -6
  11. data/lib/semantic_logger/formatters/color.rb +4 -3
  12. data/lib/semantic_logger/formatters/fluentd.rb +37 -0
  13. data/lib/semantic_logger/formatters/json.rb +4 -2
  14. data/lib/semantic_logger/formatters/raw.rb +2 -2
  15. data/lib/semantic_logger/formatters/signalfx.rb +4 -3
  16. data/lib/semantic_logger/levels.rb +38 -0
  17. data/lib/semantic_logger/log.rb +11 -6
  18. data/lib/semantic_logger/loggable.rb +1 -1
  19. data/lib/semantic_logger/logger.rb +43 -1
  20. data/lib/semantic_logger/processor.rb +10 -130
  21. data/lib/semantic_logger/reporters/minitest.rb +49 -0
  22. data/lib/semantic_logger/semantic_logger.rb +40 -75
  23. data/lib/semantic_logger/version.rb +1 -1
  24. metadata +9 -81
  25. data/test/appender/async_batch_test.rb +0 -60
  26. data/test/appender/async_test.rb +0 -44
  27. data/test/appender/bugsnag_test.rb +0 -81
  28. data/test/appender/elasticsearch_http_test.rb +0 -74
  29. data/test/appender/elasticsearch_test.rb +0 -248
  30. data/test/appender/file_test.rb +0 -120
  31. data/test/appender/graylog_test.rb +0 -82
  32. data/test/appender/honeybadger_test.rb +0 -45
  33. data/test/appender/http_test.rb +0 -63
  34. data/test/appender/kafka_test.rb +0 -35
  35. data/test/appender/mongodb_test.rb +0 -104
  36. data/test/appender/new_relic_test.rb +0 -80
  37. data/test/appender/newrelic_rpm.rb +0 -14
  38. data/test/appender/sentry_test.rb +0 -47
  39. data/test/appender/splunk_http_test.rb +0 -79
  40. data/test/appender/splunk_test.rb +0 -83
  41. data/test/appender/syslog_test.rb +0 -61
  42. data/test/appender/tcp_test.rb +0 -66
  43. data/test/appender/udp_test.rb +0 -59
  44. data/test/appender/wrapper_test.rb +0 -95
  45. data/test/concerns/compatibility_test.rb +0 -117
  46. data/test/debug_as_trace_logger_test.rb +0 -81
  47. data/test/formatters/color_test.rb +0 -153
  48. data/test/formatters/default_test.rb +0 -175
  49. data/test/formatters/one_line_test.rb +0 -60
  50. data/test/formatters/signalfx_test.rb +0 -197
  51. data/test/formatters_test.rb +0 -36
  52. data/test/in_memory_appender.rb +0 -8
  53. data/test/in_memory_appender_helper.rb +0 -43
  54. data/test/in_memory_batch_appender.rb +0 -8
  55. data/test/in_memory_metrics_appender.rb +0 -13
  56. data/test/loggable_test.rb +0 -103
  57. data/test/logger_test.rb +0 -334
  58. data/test/measure_test.rb +0 -346
  59. data/test/metric/new_relic_test.rb +0 -35
  60. data/test/metric/signalfx_test.rb +0 -77
  61. data/test/semantic_logger_test.rb +0 -303
  62. data/test/test_helper.rb +0 -31
@@ -3,18 +3,18 @@ require 'socket'
3
3
 
4
4
  module SemanticLogger
5
5
  # Logging levels in order of most detailed to most severe
6
- LEVELS = %i[trace debug info warn error fatal].freeze
6
+ LEVELS = Levels::LEVELS
7
7
 
8
8
  # Return a logger for the supplied class or class_name
9
9
  def self.[](klass)
10
- SemanticLogger::Logger.new(klass)
10
+ Logger.new(klass)
11
11
  end
12
12
 
13
13
  # Sets the global default log level
14
14
  def self.default_level=(level)
15
15
  @default_level = level
16
16
  # For performance reasons pre-calculate the level index
17
- @default_level_index = level_to_index(level)
17
+ @default_level_index = Levels.index(level)
18
18
  end
19
19
 
20
20
  # Returns the global default log level
@@ -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? ? 65_535 : level_to_index(level)
38
+ @backtrace_level_index = level.nil? ? 65_535 : Levels.index(level)
39
39
  end
40
40
 
41
41
  # Returns the current backtrace level
@@ -152,19 +152,16 @@ module SemanticLogger
152
152
  # logger.info "Hello World"
153
153
  # logger.debug("Login time", user: 'Joe', duration: 100, ip_address: '127.0.0.1')
154
154
  def self.add_appender(options, deprecated_level = nil, &block)
155
- options = options.is_a?(Hash) ? options.dup : convert_old_appender_args(options, deprecated_level)
156
- appender = SemanticLogger::Appender.factory(options, &block)
157
- @appenders << appender
158
-
155
+ appender = Logger.processor.appenders.add(options, deprecated_level, &block)
159
156
  # Start appender thread if it is not already running
160
- SemanticLogger::Processor.start
157
+ Logger.processor.start
161
158
  appender
162
159
  end
163
160
 
164
161
  # Remove an existing appender
165
162
  # Currently only supports appender instances
166
163
  def self.remove_appender(appender)
167
- @appenders.delete(appender)
164
+ Logger.processor.appenders.delete(appender)
168
165
  end
169
166
 
170
167
  # Returns [SemanticLogger::Subscriber] a copy of the list of active
@@ -172,30 +169,28 @@ module SemanticLogger
172
169
  # Use SemanticLogger.add_appender and SemanticLogger.remove_appender
173
170
  # to manipulate the active appenders list
174
171
  def self.appenders
175
- @appenders.clone
172
+ Logger.processor.appenders.to_a
176
173
  end
177
174
 
178
175
  # Flush all queued log entries disk, database, etc.
179
176
  # All queued log messages are written and then each appender is flushed in turn.
180
177
  def self.flush
181
- SemanticLogger::Processor.instance.flush
178
+ Logger.processor.flush
182
179
  end
183
180
 
184
181
  # Close all appenders and flush any outstanding messages.
185
182
  def self.close
186
- SemanticLogger::Processor.instance.close
183
+ Logger.processor.close
187
184
  end
188
185
 
189
186
  # After forking an active process call SemanticLogger.reopen to re-open
190
187
  # any open file handles etc to resources.
191
188
  #
192
189
  # Note:
193
- # Not all appenders implement reopen.
190
+ # Not all appender's implement reopen.
194
191
  # Check the code for each appender you are using before relying on this behavior.
195
192
  def self.reopen
196
- @appenders.each { |appender| appender.reopen if appender.respond_to?(:reopen) }
197
- # After a fork the appender thread is not running, start it if it is not running.
198
- SemanticLogger::Processor.start
193
+ Logger.processor.reopen
199
194
  end
200
195
 
201
196
  # Supply a callback to be called whenever a log entry is created.
@@ -223,7 +218,7 @@ module SemanticLogger
223
218
  # * This callback is called within the thread of the application making the logging call.
224
219
  # * If these callbacks are slow they will slow down the application.
225
220
  def self.on_log(object = nil, &block)
226
- Processor.instance.appender.on_log(object, &block)
221
+ Logger.subscribe(object, &block)
227
222
  end
228
223
 
229
224
  # Add signal handlers for Semantic Logger
@@ -443,79 +438,49 @@ module SemanticLogger
443
438
  # explicitly. I.e. That do not rely on the global default level
444
439
  def self.silence(new_level = :error)
445
440
  current_index = Thread.current[:semantic_logger_silence]
446
- Thread.current[:semantic_logger_silence] = SemanticLogger.level_to_index(new_level)
441
+ Thread.current[:semantic_logger_silence] = Levels.index(new_level)
447
442
  yield
448
443
  ensure
449
444
  Thread.current[:semantic_logger_silence] = current_index
450
445
  end
451
446
 
452
- def self.default_level_index
453
- Thread.current[:semantic_logger_silence] || @default_level_index
447
+ # Returns [Integer] the number of log entries waiting to be written to the appenders.
448
+ #
449
+ # When this number grows it is because the logging appender thread is not
450
+ # able to write to the appenders fast enough. Either reduce the amount of
451
+ # logging, increase the log level, reduce the number of appenders, or
452
+ # look into speeding up the appenders themselves
453
+ def self.queue_size
454
+ Logger.processor.queue.size
454
455
  end
455
456
 
456
- # private_class_method :default_level_index
457
-
458
- # Returns the symbolic level for the supplied level index
459
- def self.index_to_level(level_index)
460
- LEVELS[level_index]
457
+ # Returns the check_interval which is the number of messages between checks
458
+ # to determine if the appender thread is falling behind.
459
+ def self.lag_check_interval
460
+ Logger.processor.lag_check_interval
461
461
  end
462
462
 
463
- # private_class_method :index_to_level
464
-
465
- # Internal method to return the log level as an internal index
466
- # Also supports mapping the ::Logger levels to SemanticLogger levels
467
- def self.level_to_index(level)
468
- return if level.nil?
469
-
470
- index =
471
- if level.is_a?(Symbol)
472
- LEVELS.index(level)
473
- elsif level.is_a?(String)
474
- level = level.downcase.to_sym
475
- LEVELS.index(level)
476
- elsif level.is_a?(Integer) && defined?(::Logger::Severity)
477
- # Mapping of Rails and Ruby Logger levels to SemanticLogger levels
478
- @map_levels ||= begin
479
- levels = []
480
- ::Logger::Severity.constants.each do |constant|
481
- levels[::Logger::Severity.const_get(constant)] =
482
- LEVELS.find_index(constant.downcase.to_sym) || LEVELS.find_index(:error)
483
- end
484
- levels
485
- end
486
- @map_levels[level]
487
- end
488
- raise "Invalid level:#{level.inspect} being requested. Must be one of #{LEVELS.inspect}" unless index
489
- index
463
+ # Set the check_interval which is the number of messages between checks
464
+ # to determine if the appender thread is falling behind.
465
+ def self.lag_check_interval=(lag_check_interval)
466
+ Logger.processor.lag_check_interval = lag_check_interval
490
467
  end
491
468
 
492
- # private_class_method :level_to_index
493
-
494
- # Backward compatibility
495
- def self.convert_old_appender_args(appender, level)
496
- options = {}
497
- options[:level] = level if level
498
-
499
- if appender.is_a?(String)
500
- options[:file_name] = appender
501
- elsif appender.is_a?(IO)
502
- options[:io] = appender
503
- elsif appender.is_a?(Symbol) || appender.is_a?(Subscriber)
504
- options[:appender] = appender
505
- else
506
- options[:logger] = appender
507
- end
508
- warn "[DEPRECATED] SemanticLogger.add_appender parameters have changed. Please use: #{options.inspect}"
509
- options
469
+ # Returns the amount of time in seconds
470
+ # to determine if the appender thread is falling behind.
471
+ def self.lag_threshold_s
472
+ Logger.processor.lag_threshold_s
510
473
  end
511
474
 
512
- private_class_method :convert_old_appender_args
475
+ def self.default_level_index
476
+ Thread.current[:semantic_logger_silence] || @default_level_index
477
+ end
513
478
 
514
- @appenders = Concurrent::Array.new
479
+ private
515
480
 
516
481
  # Initial default Level for all new instances of SemanticLogger::Logger
517
482
  @default_level = :info
518
- @default_level_index = level_to_index(@default_level)
483
+ @default_level_index = Levels.index(@default_level)
519
484
  @backtrace_level = :error
520
- @backtrace_level_index = level_to_index(@backtrace_level)
485
+ @backtrace_level_index = Levels.index(@backtrace_level)
521
486
  end
@@ -1,3 +1,3 @@
1
1
  module SemanticLogger
2
- VERSION = '4.3.1'.freeze
2
+ VERSION = '4.4.0'.freeze
3
3
  end
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: 4.3.1
4
+ version: 4.4.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: 2018-11-11 00:00:00.000000000 Z
11
+ date: 2019-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -49,6 +49,7 @@ files:
49
49
  - lib/semantic_logger/appender/kafka.rb
50
50
  - lib/semantic_logger/appender/mongodb.rb
51
51
  - lib/semantic_logger/appender/new_relic.rb
52
+ - lib/semantic_logger/appender/rabbitmq.rb
52
53
  - lib/semantic_logger/appender/sentry.rb
53
54
  - lib/semantic_logger/appender/splunk.rb
54
55
  - lib/semantic_logger/appender/splunk_http.rb
@@ -56,6 +57,7 @@ files:
56
57
  - lib/semantic_logger/appender/tcp.rb
57
58
  - lib/semantic_logger/appender/udp.rb
58
59
  - lib/semantic_logger/appender/wrapper.rb
60
+ - lib/semantic_logger/appenders.rb
59
61
  - lib/semantic_logger/base.rb
60
62
  - lib/semantic_logger/concerns/compatibility.rb
61
63
  - lib/semantic_logger/core_ext/thread.rb
@@ -64,6 +66,7 @@ files:
64
66
  - lib/semantic_logger/formatters/base.rb
65
67
  - lib/semantic_logger/formatters/color.rb
66
68
  - lib/semantic_logger/formatters/default.rb
69
+ - lib/semantic_logger/formatters/fluentd.rb
67
70
  - lib/semantic_logger/formatters/json.rb
68
71
  - lib/semantic_logger/formatters/one_line.rb
69
72
  - lib/semantic_logger/formatters/raw.rb
@@ -71,6 +74,7 @@ files:
71
74
  - lib/semantic_logger/formatters/syslog.rb
72
75
  - lib/semantic_logger/formatters/syslog_cee.rb
73
76
  - lib/semantic_logger/jruby/garbage_collection_logger.rb
77
+ - lib/semantic_logger/levels.rb
74
78
  - lib/semantic_logger/log.rb
75
79
  - lib/semantic_logger/loggable.rb
76
80
  - lib/semantic_logger/logger.rb
@@ -78,48 +82,11 @@ files:
78
82
  - lib/semantic_logger/metric/signalfx.rb
79
83
  - lib/semantic_logger/metric/statsd.rb
80
84
  - lib/semantic_logger/processor.rb
85
+ - lib/semantic_logger/reporters/minitest.rb
81
86
  - lib/semantic_logger/semantic_logger.rb
82
87
  - lib/semantic_logger/subscriber.rb
83
88
  - lib/semantic_logger/utils.rb
84
89
  - lib/semantic_logger/version.rb
85
- - test/appender/async_batch_test.rb
86
- - test/appender/async_test.rb
87
- - test/appender/bugsnag_test.rb
88
- - test/appender/elasticsearch_http_test.rb
89
- - test/appender/elasticsearch_test.rb
90
- - test/appender/file_test.rb
91
- - test/appender/graylog_test.rb
92
- - test/appender/honeybadger_test.rb
93
- - test/appender/http_test.rb
94
- - test/appender/kafka_test.rb
95
- - test/appender/mongodb_test.rb
96
- - test/appender/new_relic_test.rb
97
- - test/appender/newrelic_rpm.rb
98
- - test/appender/sentry_test.rb
99
- - test/appender/splunk_http_test.rb
100
- - test/appender/splunk_test.rb
101
- - test/appender/syslog_test.rb
102
- - test/appender/tcp_test.rb
103
- - test/appender/udp_test.rb
104
- - test/appender/wrapper_test.rb
105
- - test/concerns/compatibility_test.rb
106
- - test/debug_as_trace_logger_test.rb
107
- - test/formatters/color_test.rb
108
- - test/formatters/default_test.rb
109
- - test/formatters/one_line_test.rb
110
- - test/formatters/signalfx_test.rb
111
- - test/formatters_test.rb
112
- - test/in_memory_appender.rb
113
- - test/in_memory_appender_helper.rb
114
- - test/in_memory_batch_appender.rb
115
- - test/in_memory_metrics_appender.rb
116
- - test/loggable_test.rb
117
- - test/logger_test.rb
118
- - test/measure_test.rb
119
- - test/metric/new_relic_test.rb
120
- - test/metric/signalfx_test.rb
121
- - test/semantic_logger_test.rb
122
- - test/test_helper.rb
123
90
  homepage: https://github.com/rocketjob/semantic_logger
124
91
  licenses:
125
92
  - Apache-2.0
@@ -139,48 +106,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
106
  - !ruby/object:Gem::Version
140
107
  version: '0'
141
108
  requirements: []
142
- rubyforge_project:
143
- rubygems_version: 2.7.7
109
+ rubygems_version: 3.0.2
144
110
  signing_key:
145
111
  specification_version: 4
146
112
  summary: Feature rich logging framework, and replacement for existing Ruby & Rails
147
113
  loggers.
148
- test_files:
149
- - test/appender/sentry_test.rb
150
- - test/appender/splunk_http_test.rb
151
- - test/appender/honeybadger_test.rb
152
- - test/appender/splunk_test.rb
153
- - test/appender/graylog_test.rb
154
- - test/appender/syslog_test.rb
155
- - test/appender/async_batch_test.rb
156
- - test/appender/newrelic_rpm.rb
157
- - test/appender/tcp_test.rb
158
- - test/appender/mongodb_test.rb
159
- - test/appender/elasticsearch_http_test.rb
160
- - test/appender/new_relic_test.rb
161
- - test/appender/wrapper_test.rb
162
- - test/appender/file_test.rb
163
- - test/appender/udp_test.rb
164
- - test/appender/async_test.rb
165
- - test/appender/kafka_test.rb
166
- - test/appender/elasticsearch_test.rb
167
- - test/appender/bugsnag_test.rb
168
- - test/appender/http_test.rb
169
- - test/logger_test.rb
170
- - test/loggable_test.rb
171
- - test/measure_test.rb
172
- - test/in_memory_batch_appender.rb
173
- - test/in_memory_appender_helper.rb
174
- - test/formatters/color_test.rb
175
- - test/formatters/signalfx_test.rb
176
- - test/formatters/one_line_test.rb
177
- - test/formatters/default_test.rb
178
- - test/semantic_logger_test.rb
179
- - test/formatters_test.rb
180
- - test/test_helper.rb
181
- - test/debug_as_trace_logger_test.rb
182
- - test/metric/new_relic_test.rb
183
- - test/metric/signalfx_test.rb
184
- - test/in_memory_metrics_appender.rb
185
- - test/concerns/compatibility_test.rb
186
- - test/in_memory_appender.rb
114
+ test_files: []
@@ -1,60 +0,0 @@
1
- require_relative '../test_helper'
2
-
3
- module Appender
4
- class AsyncBatchTest < Minitest::Test
5
- describe SemanticLogger::Appender::Async do
6
- include InMemoryAppenderHelper
7
-
8
- let :appender do
9
- InMemoryBatchAppender.new
10
- end
11
-
12
- describe 'with default batch_size' do
13
- let :appender_options do
14
- {appender: appender, batch: true}
15
- end
16
-
17
- it 'uses the batch proxy' do
18
- assert_instance_of SemanticLogger::Appender::AsyncBatch, added_appender
19
- end
20
-
21
- it 'logs messages after a flush' do
22
- logger.info('hello world1')
23
- refute appender.message
24
-
25
- logger.info('hello world2')
26
- refute appender.message
27
-
28
- logger.info('hello world3')
29
- refute appender.message
30
-
31
- # Calls flush
32
- assert logs = log_message
33
- assert_equal 3, logs.size, logs
34
- assert_equal 'hello world1', logs[0].message
35
- assert_equal 'hello world2', logs[1].message
36
- assert_equal 'hello world3', logs[2].message
37
- end
38
- end
39
-
40
- # :batch_size, :batch_seconds
41
- describe 'with batch_size 1' do
42
- let :appender_options do
43
- {appender: appender, batch: true, batch_size: 1}
44
- end
45
-
46
- it 'uses the batch proxy' do
47
- assert_instance_of SemanticLogger::Appender::AsyncBatch, added_appender
48
- end
49
-
50
- it 'logs message immediately' do
51
- logger.info('hello world')
52
-
53
- assert logs = log_message
54
- assert_equal 1, logs.size, logs
55
- assert_equal 'hello world', logs.first.message
56
- end
57
- end
58
- end
59
- end
60
- end
@@ -1,44 +0,0 @@
1
- require_relative '../test_helper'
2
-
3
- module Appender
4
- class AsyncTest < Minitest::Test
5
- describe SemanticLogger::Appender::Async do
6
- include InMemoryAppenderHelper
7
-
8
- describe 'with capped queue' do
9
- let :appender_options do
10
- {appender: appender, async: true}
11
- end
12
-
13
- it 'uses the async proxy' do
14
- assert_instance_of SemanticLogger::Appender::Async, added_appender
15
- end
16
-
17
- it 'logs message immediately' do
18
- logger.info('hello world')
19
-
20
- assert log = log_message
21
- assert_equal 'hello world', log.message
22
- end
23
-
24
- it 'uses an capped queue' do
25
- assert_instance_of SizedQueue, added_appender.queue
26
- end
27
- end
28
-
29
- describe 'with uncapped queue' do
30
- let :appender_options do
31
- {appender: appender, async: true, max_queue_size: -1}
32
- end
33
-
34
- it 'uses the async proxy' do
35
- assert_instance_of SemanticLogger::Appender::Async, added_appender
36
- end
37
-
38
- it 'uses an uncapped queue' do
39
- assert_instance_of Queue, added_appender.queue
40
- end
41
- end
42
- end
43
- end
44
- end