betterlog 0.7.2 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1d0c9076a03bc4094bd5ec7541ce8a5c916a2711a7901c5230340d6d69da81a6
4
- data.tar.gz: 8c9965f05f6cacefe03fbc2119f7c4d8d1c818b3f49171b00225210b427568a5
3
+ metadata.gz: d0808e5c0791eea5fc8603ab2b6b89bdfcad494290b7dd7e41065569aaaaae68
4
+ data.tar.gz: 0df0ef130d6f6b3ed31f940386906651d8d16a1b5f5823f8eb4aca54dd6c6e8a
5
5
  SHA512:
6
- metadata.gz: 756b6170017c03287422e5999c70f2b416ea9859895aace4f7ff3316bdb50cb66df17d72fc1a9a8d41596aff4866e929fdbdbc5bcb582f280da0150432b4b9a9
7
- data.tar.gz: 1ee36fdc3162f32947811db380bbbcb06edd27d328facf58801bbd6cfa8e4da2d1ebbee74c0aa5ce990b924fb11cccb68e5698f53fe3d6e555d36c32ab4bc6bb
6
+ metadata.gz: d53aa09dc1b81790f9582e5802b54af8ccbf7df80f599e6e82f473d16a41ef7e0daad414d4d81d71e3faab4f3c918ca92f498340f4f151da0b69309c070e6993
7
+ data.tar.gz: 3f7b71e06e31cf1d087b1a41d3b9394d38b70f4b3a76e4d973e81b44fac14d18793982f818922409991ea0804f901ad1eb7740b69f4b7d695d6c98af87f7a2b1
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.2
1
+ 0.8.0
data/betterlog.gemspec CHANGED
@@ -1,14 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: betterlog 0.7.2 ruby lib
2
+ # stub: betterlog 0.8.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "betterlog".freeze
6
- s.version = "0.7.2"
6
+ s.version = "0.8.0"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib".freeze]
10
10
  s.authors = ["betterplace Developers".freeze]
11
- s.date = "2019-11-06"
11
+ s.date = "2019-11-15"
12
12
  s.description = "This library provides structure json logging for our rails projects".freeze
13
13
  s.email = "developers@betterplace.org".freeze
14
14
  s.executables = ["betterlog".freeze, "betterlog_pusher".freeze, "betterlog_sink".freeze]
data/lib/betterlog/log.rb CHANGED
@@ -12,7 +12,7 @@ module Betterlog
12
12
  self.default_logger = Logger.new(STDERR)
13
13
 
14
14
  def logger
15
- defined?(Rails) && Rails.logger || self.class.default_logger
15
+ defined?(Rails) && Rails.respond_to?(:logger) ? Rails.logger : ::Logger.new(STDERR)
16
16
  end
17
17
 
18
18
  # Logs a message on severity info.
@@ -83,16 +83,19 @@ module Betterlog
83
83
  end
84
84
 
85
85
  # Logs a metric on severity debug, by default, this can be changed by passing
86
- # the severity: keyword.
86
+ # the severity: keyword. +name+ is for example 'Donation' and +type+
87
+ # 'Confirmation', and +value+ can be any value, but has to be somewhat
88
+ # consistent in terms of structure with +name/type+ to allow for correct
89
+ # evaluation.
87
90
  #
88
- # @param metric the name of the recorded metric.
91
+ # @param name the name of the recorded metric.
89
92
  # @param type of the recorded metric.
90
93
  # @param value of the recorded metric.
91
94
  # @param **rest additional rest is logged as well.
92
95
  # @return [ Log ] this object itself.
93
- def metric(metric:, type:, value:, **rest)
96
+ def metric(name:, type:, value:, **rest)
94
97
  protect do
95
- event = build_metric(metric: metric, type: type, value: value, **rest)
98
+ event = build_metric(name: name, type: type, value: value, **rest)
96
99
  emit event
97
100
  end
98
101
  end
@@ -103,21 +106,21 @@ module Betterlog
103
106
  # If an error occurs during measurement details about it are added to the
104
107
  # metric event.
105
108
  #
106
- # @param metric the name of the recorded metric.
109
+ # @param name the name of the recorded metric.
107
110
  # @param **rest additional rest is logged as well.
108
111
  # @param block the block around which the measure is teaken.
109
112
  # @return [ Log ] this object itself.
110
- def measure(metric:, **rest, &block)
113
+ def measure(name:, **rest, &block)
111
114
  raise ArgumentError, 'must be called with a block' unless block_given?
112
115
  time_block { yield }
113
116
  rescue => error
114
117
  e = Log::Event.ify(error)
115
118
  rest |= e.as_hash.subhash(:error_class, :backtrace, :message)
116
- rest[:message] = "#{rest[:message].inspect} while measuring metric #{metric}"
119
+ rest[:message] = "#{rest[:message].inspect} while measuring metric #{name}"
117
120
  raise error
118
121
  ensure
119
122
  protect do
120
- event = build_metric(metric: metric, type: 'seconds', value: timed_duration, **rest)
123
+ event = build_metric(name: name, type: 'duration', value: timed_duration, **rest)
121
124
  emit event
122
125
  end
123
126
  end
@@ -149,14 +152,14 @@ module Betterlog
149
152
  self
150
153
  end
151
154
 
152
- def build_metric(metric:, type:, value:, **rest)
155
+ def build_metric(name:, type:, value:, **rest)
153
156
  severity = rest.fetch(:severity, :debug)
154
157
  rest |= {
155
- message: "a metric #{metric} of type #{type}",
158
+ message: "a metric #{name} of type #{type}",
156
159
  }
157
160
  Log::Event.ify(
158
161
  {
159
- metric: metric,
162
+ name: name,
160
163
  type: type,
161
164
  value: value,
162
165
  } | rest,
@@ -1,6 +1,6 @@
1
1
  module Betterlog
2
2
  # Betterlog version
3
- VERSION = '0.7.2'
3
+ VERSION = '0.8.0'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
@@ -140,14 +140,14 @@ describe Betterlog::Log do
140
140
 
141
141
  it 'can be sent after measuring times' do
142
142
  expected_event = Log::Event.new(
143
- message: 'a metric foo of type seconds',
144
- metric: 'foo',
145
- type: 'seconds',
143
+ message: 'a metric foo of type duration',
144
+ name: 'foo',
145
+ type: 'duration',
146
146
  value: 10.0,
147
147
  timestamp: "2011-11-11T10:11:21.000Z"
148
148
  )
149
149
  expect(instance).to receive(:emit).with(expected_event)
150
- Log.measure(metric: 'foo') do
150
+ Log.measure(name: 'foo') do
151
151
  Time.dummy = Time.now + 10
152
152
  end
153
153
  end
@@ -160,8 +160,8 @@ describe Betterlog::Log do
160
160
 
161
161
  it 'adds exception information if block raises' do
162
162
  expected_event = Log::Event.new(
163
- metric: 'foo',
164
- type: 'seconds',
163
+ name: 'foo',
164
+ type: 'duration',
165
165
  value: 3.0,
166
166
  timestamp: "2011-11-11T10:11:14.000Z",
167
167
  message: '"MyEx: we were fucked" while measuring metric foo',
@@ -171,7 +171,7 @@ describe Betterlog::Log do
171
171
  expect(instance).to receive(:emit).with(expected_event)
172
172
  raised = false
173
173
  begin
174
- Log.measure(metric: 'foo') do
174
+ Log.measure(name: 'foo') do
175
175
  Time.dummy = Time.now + 3
176
176
  raise MyEx, "we were fucked"
177
177
  Time.dummy = Time.now + 7
@@ -187,36 +187,36 @@ describe Betterlog::Log do
187
187
  it 'logs metrics with a specific structure on debug log level' do
188
188
  expected_event = Log::Event.new(
189
189
  message: 'a metric controller.action of type ms',
190
- metric: 'controller.action',
190
+ name: 'controller.action',
191
191
  type: 'ms',
192
192
  value: 0.123,
193
193
  )
194
194
  expect(instance).to receive(:emit).with(expected_event)
195
- Log.metric(metric: 'controller.action', type: 'ms', value: 0.123)
195
+ Log.metric(name: 'controller.action', type: 'ms', value: 0.123)
196
196
  end
197
197
 
198
198
  it 'logs metrics on a given log level' do
199
199
  expected_event = Log::Event.new(
200
200
  message: 'a metric controller.action of type ms',
201
- metric: 'controller.action',
201
+ name: 'controller.action',
202
202
  type: 'ms',
203
203
  value: 0.123,
204
204
  severity: :info,
205
205
  )
206
206
  expect(instance).to receive(:emit).with(expected_event)
207
- Log.metric(severity: :info, metric: 'controller.action', type: 'ms', value: 0.123)
207
+ Log.metric(severity: :info, name: 'controller.action', type: 'ms', value: 0.123)
208
208
  end
209
209
 
210
210
  it 'logs metrics with additional data' do
211
211
  expected_event = Log::Event.new(
212
212
  message: 'a metric controller.action of type ms',
213
213
  foo: 'bar',
214
- metric: 'controller.action',
214
+ name: 'controller.action',
215
215
  type: 'ms',
216
216
  value: 0.123,
217
217
  )
218
218
  expect(instance).to receive(:emit).with(expected_event)
219
- Log.metric(metric: 'controller.action', type: 'ms', value: 0.123, foo: 'bar')
219
+ Log.metric(name: 'controller.action', type: 'ms', value: 0.123, foo: 'bar')
220
220
  end
221
221
  end
222
222
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: betterlog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - betterplace Developers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-06 00:00:00.000000000 Z
11
+ date: 2019-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gem_hadar