semantic_logger 4.2.2 → 4.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 5e2a3fa7d0cba9f44c7a64abbc17d3fe77a10174
4
- data.tar.gz: bca2b99107ef30043276c03b5ea09cacb4065129
2
+ SHA256:
3
+ metadata.gz: 951b7e0fc762a3801a11ccf9d3ca9cc503742453f39490ddd41112895d677fe7
4
+ data.tar.gz: 25c47bbee6b929b1f23fcc56ee6f34164066af52fb130ff238877d833538cb62
5
5
  SHA512:
6
- metadata.gz: 4c5afd6c5af4110f7f63adbdce4fbd419c9c33c88522d3c3a36acc3d2335dacc0d34f79bdd2775f0b0eadb9cf4d6284b0c0cbe514011bd323b346e54ca0ae525
7
- data.tar.gz: e7f2cbf6618aed0c38b10312dee1008b5eb4cf98809525826a2460c3003bb82816e043bde83dd9c56ccf9475e018e352f4cecfa14cd8674c305c3af44999ec38
6
+ metadata.gz: 9553643ca1faf2f9d124cd05333f648f4770f1249a46ec92c21b2cb41856d9d0ee62d65cb59bf097548a10b22f91b6530fe48a2138ecdca5ee997e69fd4da3ca
7
+ data.tar.gz: 25e1949848b10937692ea12fbab2d83a090c36c09cc9a005cc64a4263b8838cba9d712e628bd4f311b58ac6b416963ae759609864935faaf0efdc73501cd397c
data/README.md CHANGED
@@ -50,11 +50,7 @@ Checkout the sister project [Rocket Job](http://rocketjob.io): Ruby's missing ba
50
50
  Fully supports Semantic Logger when running jobs in the background. Complete support for job metrics
51
51
  sent via Semantic Logger to your favorite dashboards.
52
52
 
53
- ## Supports
54
-
55
- Semantic Logger is tested and supported on the following Ruby platforms:
56
- - Ruby 2.1 and higher.
57
- - JRuby 9.1 and higher.
53
+ ## Optional Dependencies
58
54
 
59
55
  The following gems are only required when their corresponding appenders are being used,
60
56
  and are therefore not automatically included by this gem:
@@ -42,6 +42,7 @@ module SemanticLogger
42
42
  @appender = appender
43
43
  @lag_check_interval = lag_check_interval
44
44
  @lag_threshold_s = lag_threshold_s
45
+ @thread = nil
45
46
 
46
47
  if max_queue_size == -1
47
48
  @queue = Queue.new
@@ -29,13 +29,13 @@ module SemanticLogger
29
29
  # regular expression. All other messages will be ignored.
30
30
  # Proc: Only include log messages where the supplied Proc returns true
31
31
  # The Proc must return true or false.
32
- def initialize(level: :error, formatter: nil, filter: nil, application: nil, host: nil, &block)
32
+ def initialize(level: :error, **args, &block)
33
33
  raise 'Bugsnag only supports :info, :warn, or :error log levels' unless %i[info warn error fatal].include?(level)
34
34
 
35
35
  # Replace the Bugsnag logger so that we can identify its log messages and not forward them to Bugsnag
36
36
  ::Bugsnag.configure { |config| config.logger = SemanticLogger[Bugsnag] }
37
37
 
38
- super(level: level, formatter: formatter, filter: filter, application: application, host: host, &block)
38
+ super(level: level, **args, &block)
39
39
  end
40
40
 
41
41
  # Returns [Hash] of parameters to send to Bugsnag.
@@ -126,6 +126,7 @@ module SemanticLogger
126
126
  filter: nil,
127
127
  application: nil,
128
128
  host: nil,
129
+ metrics: false,
129
130
  **elasticsearch_args,
130
131
  &block)
131
132
 
@@ -136,7 +137,7 @@ module SemanticLogger
136
137
  @elasticsearch_args[:url] = url if url && !elasticsearch_args[:hosts]
137
138
  @elasticsearch_args[:logger] = logger
138
139
 
139
- super(level: level, formatter: formatter, filter: filter, application: application, host: host, &block)
140
+ super(level: level, formatter: formatter, filter: filter, application: application, host: host, metrics: false, &block)
140
141
  reopen
141
142
  end
142
143
 
@@ -59,7 +59,7 @@ module SemanticLogger
59
59
  #
60
60
  # logger = SemanticLogger['test']
61
61
  # logger.info 'Hello World'
62
- def initialize(io: nil, file_name: nil, level: nil, formatter: nil, filter: nil, application: nil, host: nil, &block)
62
+ def initialize(io: nil, file_name: nil, **args, &block)
63
63
  if io
64
64
  @log = io
65
65
  else
@@ -68,7 +68,7 @@ module SemanticLogger
68
68
  reopen
69
69
  end
70
70
 
71
- super(level: level, formatter: formatter, filter: filter, application: application, host: host, &block)
71
+ super(**args, &block)
72
72
  end
73
73
 
74
74
  # After forking an active process call #reopen to re-open
@@ -82,15 +82,19 @@ module SemanticLogger
82
82
  # application: [String]
83
83
  # Name of this application to appear in log messages.
84
84
  # Default: SemanticLogger.application
85
- def initialize(url: 'udp://localhost:12201', max_size: 'WAN', gelf_options: {}, level_map: LevelMap.new,
86
- level: nil, formatter: nil, filter: nil, application: nil, host: nil, &block)
85
+ def initialize(url: 'udp://localhost:12201',
86
+ max_size: 'WAN',
87
+ gelf_options: {},
88
+ level_map: LevelMap.new,
89
+ **args,
90
+ &block)
87
91
 
88
92
  @url = url
89
93
  @max_size = max_size
90
94
  @gelf_options = gelf_options
91
95
  @level_map = level_map.is_a?(LevelMap) ? level_map : LevelMap.new(level_map)
92
96
 
93
- super(level: level, formatter: formatter, filter: filter, application: application, host: host, &block)
97
+ super(**args, &block)
94
98
  reopen
95
99
  end
96
100
 
@@ -37,8 +37,8 @@ module SemanticLogger
37
37
  # application: [String]
38
38
  # Name of this application to appear in log messages.
39
39
  # Default: SemanticLogger.application
40
- def initialize(level: :error, formatter: nil, filter: nil, application: nil, host: nil, &block)
41
- super(level: level, formatter: formatter, filter: filter, application: application, host: host, &block)
40
+ def initialize(level: :error, **args, &block)
41
+ super(level: level, **args, &block)
42
42
  end
43
43
 
44
44
  # Send an error notification to honeybadger
@@ -88,11 +88,7 @@ module SemanticLogger
88
88
  open_timeout: 2.0,
89
89
  read_timeout: 1.0,
90
90
  continue_timeout: 1.0,
91
- level: nil,
92
- formatter: nil,
93
- filter: nil,
94
- application: nil,
95
- host: nil,
91
+ **args,
96
92
  &block)
97
93
 
98
94
  @url = url
@@ -133,7 +129,7 @@ module SemanticLogger
133
129
  end
134
130
  @http = nil
135
131
 
136
- super(level: level, formatter: formatter, filter: filter, application: application, host: host, &block)
132
+ super(**args, &block)
137
133
  reopen
138
134
  end
139
135
 
@@ -111,11 +111,15 @@ module SemanticLogger
111
111
  # application: [String]
112
112
  # Name of this application to appear in log messages.
113
113
  # Default: SemanticLogger.application
114
+ #
115
+ # metrics: [Boolean]
116
+ # Send metrics only events to kafka.
117
+ # Default: true
114
118
  def initialize(seed_brokers:, client_id: 'semantic-logger', connect_timeout: nil, socket_timeout: nil,
115
119
  ssl_ca_cert: nil, ssl_client_cert: nil, ssl_client_cert_key: nil,
116
120
  topic: 'log_messages', partition: nil, partition_key: nil, key: nil,
117
121
  delivery_threshold: 100, delivery_interval: 10,
118
- level: nil, formatter: nil, filter: nil, application: nil, host: nil, &block)
122
+ metrics: true, **args, &block)
119
123
 
120
124
  @seed_brokers = seed_brokers
121
125
  @client_id = client_id
@@ -131,7 +135,7 @@ module SemanticLogger
131
135
  @delivery_threshold = delivery_threshold
132
136
  @delivery_interval = delivery_interval
133
137
 
134
- super(level: level, formatter: formatter, filter: filter, application: application, host: host, &block)
138
+ super(metrics: metrics, **args, &block)
135
139
  reopen
136
140
  end
137
141
 
@@ -103,8 +103,13 @@ module SemanticLogger
103
103
  # application: [String]
104
104
  # Name of this application to appear in log messages.
105
105
  # Default: SemanticLogger.application
106
- def initialize(uri:, collection_name: 'semantic_logger', write_concern: 0, collection_size: 1024 ** 3, collection_max: nil,
107
- level: nil, formatter: nil, filter: nil, host: nil, application: nil, &block)
106
+ def initialize(uri:,
107
+ collection_name: 'semantic_logger',
108
+ write_concern: 0,
109
+ collection_size: 1024 ** 3,
110
+ collection_max: nil,
111
+ **args,
112
+ &block)
108
113
 
109
114
  @client = Mongo::Client.new(uri, logger: logger)
110
115
  @collection_name = collection_name
@@ -120,7 +125,7 @@ module SemanticLogger
120
125
  # Create the collection and necessary indexes
121
126
  create_indexes
122
127
 
123
- super(level: level, formatter: formatter, filter: filter, application: application, host: host, &block)
128
+ super(**args, &block)
124
129
  end
125
130
 
126
131
  # After forking an active process call #reopen to re-open
@@ -31,14 +31,8 @@ module SemanticLogger
31
31
  # regular expression. All other messages will be ignored.
32
32
  # Proc: Only include log messages where the supplied Proc returns true
33
33
  # The Proc must return true or false.
34
- def initialize(level: :error,
35
- formatter: nil,
36
- filter: nil,
37
- application: nil,
38
- host: nil,
39
- &block)
40
-
41
- super(level: level, formatter: formatter, filter: filter, application: application, host: host, &block)
34
+ def initialize(level: :error, **args, &block)
35
+ super(level: level, **args, &block)
42
36
  end
43
37
 
44
38
  # Returns [Hash] of parameters to send to New Relic.
@@ -37,10 +37,10 @@ module SemanticLogger
37
37
  # application: [String]
38
38
  # Name of this application to appear in log messages.
39
39
  # Default: SemanticLogger.application
40
- def initialize(level: :error, formatter: nil, filter: nil, application: nil, host: nil, &block)
40
+ def initialize(level: :error, **args, &block)
41
41
  # Replace the Sentry Raven logger so that we can identify its log messages and not forward them to Sentry
42
42
  Raven.configure { |config| config.logger = SemanticLogger[Raven] }
43
- super(level: level, formatter: formatter, filter: filter, application: application, host: host, &block)
43
+ super(level: level, **args, &block)
44
44
  end
45
45
 
46
46
  # Send an error notification to sentry
@@ -49,12 +49,14 @@ module SemanticLogger
49
49
  return false if log.name == 'Raven'
50
50
 
51
51
  context = formatter.call(log, self)
52
- attrs = {
52
+ user = context.delete(:user)
53
+ tags = context.delete(:tags)
54
+ attrs = {
53
55
  level: context.delete(:level),
54
- user: context.delete(:user),
55
- tags: context.delete(:tags),
56
56
  extra: context
57
57
  }
58
+ attrs[:user] = user if user
59
+ attrs[:tags] = tags if tags
58
60
  if log.exception
59
61
  context.delete(:exception)
60
62
  Raven.capture_exception(log.exception, attrs)
@@ -88,12 +88,11 @@ module SemanticLogger
88
88
  # regular expression. All other messages will be ignored.
89
89
  # Proc: Only include log messages where the supplied Proc returns true
90
90
  # The Proc must return true or false.
91
- def initialize(index: 'main', source_type: nil,
92
- level: nil, formatter: nil, filter: nil, application: nil, host: nil, &block)
91
+ def initialize(index: 'main', source_type: nil, **args, &block)
93
92
  @index = index
94
93
  @source_type = source_type
95
94
 
96
- super(level: level, formatter: formatter, filter: filter, application: application, host: host, &block)
95
+ super(**args, &block)
97
96
  reopen
98
97
  end
99
98
 
@@ -68,15 +68,17 @@ module SemanticLogger
68
68
  # regular expression. All other messages will be ignored.
69
69
  # Proc: Only include log messages where the supplied Proc returns true
70
70
  # The Proc must return true or false.
71
- def initialize(token: nil, source_type: nil, index: nil,
72
- url:, compress: true, ssl: {}, open_timeout: 2.0, read_timeout: 1.0, continue_timeout: 1.0,
73
- level: nil, formatter: nil, filter: nil, application: nil, host: nil, &block)
71
+ def initialize(token: nil,
72
+ source_type: nil,
73
+ index: nil,
74
+ compress: true,
75
+ **args,
76
+ &block)
74
77
 
75
78
  @source_type = source_type
76
79
  @index = index
77
80
 
78
- super(url: url, compress: compress, ssl: ssl, read_timeout: read_timeout, open_timeout: open_timeout, continue_timeout: continue_timeout,
79
- level: level, formatter: formatter, filter: filter, application: application, host: host, &block)
81
+ super(compress: compress, **args, &block)
80
82
 
81
83
  # Put splunk auth token in the header of every HTTP post.
82
84
  @header['Authorization'] = "Splunk #{token}"
@@ -120,9 +120,12 @@ module SemanticLogger
120
120
  # # Change the warn level to LOG_NOTICE level instead of a the default of LOG_WARNING.
121
121
  # SemanticLogger.add_appender(appender: :syslog, level_map: {warn: ::Syslog::LOG_NOTICE})
122
122
  def initialize(url: 'syslog://localhost',
123
- facility: ::Syslog::LOG_USER, level_map: SemanticLogger::Formatters::Syslog::LevelMap.new, options: ::Syslog::LOG_PID| ::Syslog::LOG_CONS,
123
+ facility: ::Syslog::LOG_USER,
124
+ level_map: SemanticLogger::Formatters::Syslog::LevelMap.new,
125
+ options: ::Syslog::LOG_PID | ::Syslog::LOG_CONS,
124
126
  tcp_client: {},
125
- level: nil, formatter: nil, filter: nil, application: nil, host: nil, &block)
127
+ **args,
128
+ &block)
126
129
 
127
130
  @options = options
128
131
  @facility = facility
@@ -155,7 +158,7 @@ module SemanticLogger
155
158
  end
156
159
  end
157
160
 
158
- super(level: level, formatter: formatter, filter: filter, application: application, host: host, &block)
161
+ super(**args, &block)
159
162
  reopen
160
163
  end
161
164
 
@@ -164,7 +167,8 @@ module SemanticLogger
164
167
  def reopen
165
168
  case @protocol
166
169
  when :syslog
167
- ::Syslog.open(application, options, facility)
170
+ method = ::Syslog.opened? ? :reopen : :open
171
+ ::Syslog.send(method, application, options, facility)
168
172
  when :tcp
169
173
  # Use the local logger for @remote_syslog so errors with the remote logger can be recorded locally.
170
174
  @tcp_client_options[:logger] = logger
@@ -182,7 +182,7 @@ module SemanticLogger
182
182
  # connect_retry_count: 5
183
183
  # )
184
184
  def initialize(separator: "\n",
185
- level: nil, formatter: nil, filter: nil, application: nil, host: nil,
185
+ level: nil, formatter: nil, filter: nil, application: nil, host: nil, metrics: false,
186
186
  **tcp_client_args, &block)
187
187
  @separator = separator
188
188
  @tcp_client_args = tcp_client_args
@@ -48,6 +48,10 @@ module SemanticLogger
48
48
  # Proc: Only include log messages where the supplied Proc returns true
49
49
  # The Proc must return true or false.
50
50
  #
51
+ # metrics: [Boolean]
52
+ # Send metrics only events over udp.
53
+ # Default: true
54
+ #
51
55
  # Limitations:
52
56
  # * UDP packet size is limited by the connected network and any routers etc
53
57
  # that the message has to traverse. See https://en.wikipedia.org/wiki/Maximum_transmission_unit
@@ -57,11 +61,11 @@ module SemanticLogger
57
61
  # appender: :udp,
58
62
  # server: 'server:3300'
59
63
  # )
60
- def initialize(server:, udp_flags: 0, level: nil, formatter: nil, filter: nil, application: nil, host: nil, &block)
64
+ def initialize(server:, udp_flags: 0, metrics: true, **args, &block)
61
65
  @server = server
62
66
  @udp_flags = udp_flags
63
67
 
64
- super(level: level, formatter: formatter, filter: filter, application: application, host: host, &block)
68
+ super(metrics: metrics, **args, &block)
65
69
  reopen
66
70
  end
67
71
 
@@ -39,7 +39,7 @@ module SemanticLogger
39
39
  # logger.info('Hello World', some: :payload)
40
40
  #
41
41
  # Install the `rails_semantic_logger` gem to replace the Rails logger with Semantic Logger.
42
- def initialize(logger:, level: nil, formatter: nil, filter: nil, application: nil, host: nil, &block)
42
+ def initialize(logger:, **args, &block)
43
43
  @logger = logger
44
44
 
45
45
  # Check if the custom appender responds to all the log levels. For example Ruby ::Logger
@@ -48,7 +48,7 @@ module SemanticLogger
48
48
  raise(ArgumentError, "Supplied logger does not implement:#{does_not_implement}. It must implement all of #{LEVELS[1..-1].inspect}")
49
49
  end
50
50
 
51
- super(level: level, formatter: formatter, filter: filter, application: application, host: host, &block)
51
+ super(**args, &block)
52
52
  end
53
53
 
54
54
  # Pass log calls to the underlying Rails, log4j or Ruby logger
@@ -136,7 +136,7 @@ module SemanticLogger
136
136
 
137
137
  backtrace =
138
138
  if thread == Thread.current
139
- Log.cleanse_backtrace
139
+ Utils.extract_backtrace
140
140
  else
141
141
  log.thread_name = thread.name
142
142
  log.tags = (thread[:semantic_logger_tags] || []).clone
@@ -109,9 +109,9 @@ module SemanticLogger
109
109
  end
110
110
 
111
111
  if backtrace
112
- self.backtrace = Utils.cleanse_backtrace(backtrace)
112
+ self.backtrace = Utils.extract_backtrace(backtrace)
113
113
  elsif level_index >= SemanticLogger.backtrace_level_index
114
- self.backtrace = Utils.cleanse_backtrace
114
+ self.backtrace = Utils.extract_backtrace
115
115
  end
116
116
 
117
117
  if metric
@@ -149,7 +149,7 @@ module SemanticLogger
149
149
  if result.is_a?(String)
150
150
  message = message.nil? ? result : "#{message} -- #{result}"
151
151
  assign(message: message, payload: payload, exception: exception)
152
- elsif message.nil? && result.is_a?(Hash) && [:message, :payload, :exception].any? { |k| result.key? k }
152
+ elsif message.nil? && result.is_a?(Hash) && %i[message payload exception].any? { |k| result.key? k }
153
153
  assign(result)
154
154
  elsif payload&.respond_to?(:merge)
155
155
  assign(message: message, payload: payload.merge(result), exception: exception)
@@ -295,9 +295,9 @@ module SemanticLogger
295
295
  (self.context ||= {})[key] = value
296
296
  end
297
297
 
298
- # A metric only event has a metric but no message, exception, or payload.
298
+ # A metric only event has a metric but no message or exception.
299
299
  def metric_only?
300
- metric && message.nil? && exception.nil? && payload.nil?
300
+ metric && message.nil? && exception.nil?
301
301
  end
302
302
  end
303
303
  end
@@ -37,16 +37,9 @@ module SemanticLogger
37
37
  # regular expression. All other messages will be ignored.
38
38
  # Proc: Only include log messages where the supplied Proc returns true
39
39
  # The Proc must return true or false.
40
- def initialize(prefix: 'Custom',
41
- level: nil,
42
- formatter: nil,
43
- filter: nil,
44
- application: nil,
45
- host: nil,
46
- &block)
47
-
40
+ def initialize(prefix: 'Custom', **args, &block)
48
41
  @prefix = prefix
49
- super(level: level, formatter: formatter, filter: filter, application: application, host: host, &block)
42
+ super(**args, &block)
50
43
  end
51
44
 
52
45
  # Returns metric name to use.
@@ -76,28 +76,13 @@ module SemanticLogger
76
76
  def initialize(token:,
77
77
  dimensions: nil,
78
78
  url: 'https://ingest.signalfx.com',
79
- open_timeout: 2.0,
80
- read_timeout: 1.0,
81
- continue_timeout: 1.0,
82
- filter: nil,
83
- application: nil,
84
- host: nil,
85
79
  formatter: nil,
80
+ **args,
86
81
  &block)
87
82
 
88
83
  formatter ||= SemanticLogger::Formatters::Signalfx.new(token: token, dimensions: dimensions)
89
84
 
90
- super(
91
- url: url,
92
- read_timeout: read_timeout,
93
- open_timeout: open_timeout,
94
- continue_timeout: continue_timeout,
95
- filter: filter,
96
- application: application,
97
- host: host,
98
- formatter: formatter,
99
- &block
100
- )
85
+ super(url: url, formatter: formatter, **args, &block)
101
86
 
102
87
  @header['X-SF-TOKEN'] = token
103
88
  @full_url = "#{url}/#{END_POINT}"
@@ -5,7 +5,7 @@ module SemanticLogger
5
5
  class Subscriber < SemanticLogger::Base
6
6
  # Every appender has its own formatter
7
7
  attr_reader :formatter
8
- attr_writer :application, :host, :logger
8
+ attr_writer :application, :host, :logger, :metrics
9
9
 
10
10
  # Returns the current log level if set, otherwise it logs everything it receives.
11
11
  def level
@@ -59,7 +59,7 @@ module SemanticLogger
59
59
 
60
60
  # Whether this log entry meets the criteria to be logged by this appender.
61
61
  def should_log?(log)
62
- super(log) && !log.metric_only?
62
+ super(log) && (log.metric_only? ? metrics? : true)
63
63
  end
64
64
 
65
65
  private
@@ -88,10 +88,15 @@ module SemanticLogger
88
88
  # host: [String]
89
89
  # Name of this host to appear in log messages.
90
90
  # Default: SemanticLogger.host
91
- def initialize(level: nil, formatter: nil, filter: nil, application: nil, host: nil, &block)
91
+ #
92
+ # metrics: [Boolean]
93
+ # Whether to log metric only entries with this subscriber.
94
+ # Default: false
95
+ def initialize(level: nil, formatter: nil, filter: nil, application: nil, host: nil, metrics: false, &block)
92
96
  self.formatter = block || formatter
93
97
  @application = application
94
98
  @host = host
99
+ @metrics = metrics
95
100
 
96
101
  # Subscribers don't take a class name, so use this class name if a subscriber
97
102
  # is logged to directly.
@@ -104,5 +109,10 @@ module SemanticLogger
104
109
  def level_index
105
110
  @level_index || 0
106
111
  end
112
+
113
+ # Whether to log metric only entries with this subscriber
114
+ def metrics?
115
+ @metrics
116
+ end
107
117
  end
108
118
  end
@@ -1,4 +1,6 @@
1
1
  module SemanticLogger
2
+ # Internal-use only utility functions for Semantic Logger.
3
+ # Not intended for public use.
2
4
  module Utils
3
5
  def self.constantize_symbol(symbol, namespace = 'SemanticLogger::Appender')
4
6
  klass = "#{namespace}::#{camelize(symbol.to_s)}"
@@ -37,11 +39,26 @@ module SemanticLogger
37
39
  SELF_PATTERN = File.join('lib', 'semantic_logger')
38
40
 
39
41
  # Extract the backtrace leaving out the last few Semantic Logger lines.
40
- def self.cleanse_backtrace(stack = caller)
42
+ def self.extract_backtrace(stack = caller)
41
43
  while (first = stack.first) && first.include?(SELF_PATTERN)
42
44
  stack.shift
43
45
  end
44
46
  stack
45
47
  end
48
+
49
+ # Strips off all gems and built-in ruby code paths from the top of the stack until application code is found.
50
+ def self.strip_backtrace(stack = caller)
51
+ while (first = stack.first) && system_path?(first)
52
+ stack.shift
53
+ end
54
+ stack
55
+ end
56
+
57
+ GEM_ROOT = File.expand_path('../../..', __dir__) + '/'
58
+
59
+ def self.system_path?(path)
60
+ path.start_with?(GEM_ROOT) ||
61
+ path.start_with?(RbConfig::CONFIG['rubylibdir'])
62
+ end
46
63
  end
47
64
  end
@@ -1,3 +1,3 @@
1
1
  module SemanticLogger
2
- VERSION = '4.2.2'.freeze
2
+ VERSION = '4.3.0'.freeze
3
3
  end
@@ -66,6 +66,15 @@ module Appender
66
66
  assert_equal @message, hash[:message], hash
67
67
  end
68
68
  end
69
+
70
+ it 'does not send metric only notifications' do
71
+ exception = hash = nil
72
+ Bugsnag.stub(:notify, ->(exc, h) { exception = exc; hash = h }) do
73
+ @appender.debug metric: 'my/custom/metric', payload: {hello: :world}
74
+ end
75
+ assert_nil exception
76
+ assert_nil hash
77
+ end
69
78
  end
70
79
  end
71
80
  end
@@ -64,6 +64,16 @@ module Appender
64
64
  @appender.debug exc
65
65
  assert_match(/\d+-\d+-\d+ \d+:\d+:\d+.\d+ D \[\d+:#{@thread_name}\] SemanticLogger::Appender::File -- Exception: StandardError: StandardError\n\n/, @io.string)
66
66
  end
67
+
68
+ it 'ignores metric only messages' do
69
+ @appender.debug metric: 'my/custom/metric'
70
+ assert_equal '', @io.string
71
+ end
72
+
73
+ it 'ignores metric only messages with payload' do
74
+ @appender.debug metric: 'my/custom/metric', payload: {hello: :world}
75
+ assert_equal '', @io.string
76
+ end
67
77
  end
68
78
 
69
79
  describe 'for each log level' do
@@ -66,6 +66,15 @@ module Appender
66
66
  assert payload = params[:payload], params
67
67
  assert_equal 4, payload[:key3], payload
68
68
  end
69
+
70
+ it 'does not send metric only notifications' do
71
+ exception = hash = nil
72
+ NewRelic::Agent.stub(:notice_error, ->(exc, h) { exception = exc; hash = h }) do
73
+ @appender.debug metric: 'my/custom/metric', payload: {hello: :world}
74
+ end
75
+ assert_nil exception
76
+ assert_nil hash
77
+ end
69
78
  end
70
79
  end
71
80
  end
data/test/logger_test.rb CHANGED
@@ -89,10 +89,10 @@ class LoggerTest < Minitest::Test
89
89
  end
90
90
 
91
91
  it 'logs payload from block' do
92
- logger.send(level) { { 'test_key1' => 'hello world', 'test_key2' => payload} }
92
+ logger.send(level) { {'test_key1' => 'hello world', 'test_key2' => payload} }
93
93
 
94
94
  assert log = log_message
95
- assert_equal log.payload, { 'test_key1' => 'hello world', 'test_key2' => payload }
95
+ assert_equal log.payload, 'test_key1' => 'hello world', 'test_key2' => payload
96
96
  end
97
97
 
98
98
  it 'logs payload only' do
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.2.2
4
+ version: 4.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: 2018-04-11 00:00:00.000000000 Z
11
+ date: 2018-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -140,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
140
  version: '0'
141
141
  requirements: []
142
142
  rubyforge_project:
143
- rubygems_version: 2.6.13
143
+ rubygems_version: 2.7.6
144
144
  signing_key:
145
145
  specification_version: 4
146
146
  summary: Feature rich logging framework, and replacement for existing Ruby & Rails