betterlog 0.8.0 → 0.8.1

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: d0808e5c0791eea5fc8603ab2b6b89bdfcad494290b7dd7e41065569aaaaae68
4
- data.tar.gz: 0df0ef130d6f6b3ed31f940386906651d8d16a1b5f5823f8eb4aca54dd6c6e8a
3
+ metadata.gz: 669ea0d62356d1741924aa51d8648fc8968cc32a910a9bcd96f88c90d91e494c
4
+ data.tar.gz: db1a0fb6aea128b0bff226bb912c0d66f0ba40b8955a854a1c6f02fb22e798f9
5
5
  SHA512:
6
- metadata.gz: d53aa09dc1b81790f9582e5802b54af8ccbf7df80f599e6e82f473d16a41ef7e0daad414d4d81d71e3faab4f3c918ca92f498340f4f151da0b69309c070e6993
7
- data.tar.gz: 3f7b71e06e31cf1d087b1a41d3b9394d38b70f4b3a76e4d973e81b44fac14d18793982f818922409991ea0804f901ad1eb7740b69f4b7d695d6c98af87f7a2b1
6
+ metadata.gz: a32f1c9ed9581edba4047bc14691a3a94653a553897b478361d012871ae2aa57843786642e41313c836f5fc5bf284153f5bc6bb49e734daf603d19d8cb70d37c
7
+ data.tar.gz: 56e67e0133c821f0f945328c0d3ddcacbf42503d4b0d21b2e4d454b52291bf95737c38493840828d8ceb308a6c6b1d8ca53c0b8abd17eccf3684511104692520
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.0
1
+ 0.8.1
data/betterlog.gemspec CHANGED
@@ -1,9 +1,9 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: betterlog 0.8.0 ruby lib
2
+ # stub: betterlog 0.8.1 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "betterlog".freeze
6
- s.version = "0.8.0"
6
+ s.version = "0.8.1"
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]
data/config/log.yml CHANGED
@@ -21,7 +21,7 @@ development: &development
21
21
  timestamp: {%lt%timestamp}
22
22
  severity: {severity}
23
23
  message: "{message}"
24
- metric: {metric} {value} {type}
24
+ metric: {metric} {value}
25
25
  error_class: {error_class}
26
26
  backtrace: {%O%backtrace}
27
27
  host: {host}
@@ -33,7 +33,7 @@ development: &development
33
33
  {%0.1s%severity} [{%lt%timestamp} #{%d%pid}] {%5s%severity} --
34
34
  {program}: {message}
35
35
  metric: >
36
- {%ft%timestamp} {metric} {value} {type}
36
+ {%ft%timestamp} {metric} {value}
37
37
  config_files:
38
38
  rails:
39
39
  - log/development.log
data/lib/betterlog/log.rb CHANGED
@@ -83,19 +83,18 @@ 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. +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
86
+ # the severity: keyword. +name+ is for example 'Donation.Confirmation' and
87
+ # +value+ can be any value, but has to be somewhat consistent in terms of
88
+ # structure with +name+ to allow for correct
89
89
  # evaluation.
90
90
  #
91
91
  # @param name the name of the recorded metric.
92
- # @param type of the recorded metric.
93
92
  # @param value of the recorded metric.
94
93
  # @param **rest additional rest is logged as well.
95
94
  # @return [ Log ] this object itself.
96
- def metric(name:, type:, value:, **rest)
95
+ def metric(name:, value:, **rest)
97
96
  protect do
98
- event = build_metric(name: name, type: type, value: value, **rest)
97
+ event = build_metric(name: name, value: value, **rest)
99
98
  emit event
100
99
  end
101
100
  end
@@ -120,7 +119,7 @@ module Betterlog
120
119
  raise error
121
120
  ensure
122
121
  protect do
123
- event = build_metric(name: name, type: 'duration', value: timed_duration, **rest)
122
+ event = build_metric(name: name, value: timed_duration, **rest)
124
123
  emit event
125
124
  end
126
125
  end
@@ -152,16 +151,16 @@ module Betterlog
152
151
  self
153
152
  end
154
153
 
155
- def build_metric(name:, type:, value:, **rest)
156
- severity = rest.fetch(:severity, :debug)
154
+ def build_metric(name:, value:, **rest)
155
+ severity = rest.fetch(:severity, :info)
157
156
  rest |= {
158
- message: "a metric #{name} of type #{type}",
157
+ message: "a metric #{name}=#{value}",
159
158
  }
160
159
  Log::Event.ify(
161
160
  {
162
- name: name,
163
- type: type,
161
+ name: name,
164
162
  value: value,
163
+ type: 'metric'
165
164
  } | rest,
166
165
  severity: severity
167
166
  )
@@ -1,6 +1,6 @@
1
1
  module Betterlog
2
2
  # Betterlog version
3
- VERSION = '0.8.0'
3
+ VERSION = '0.8.1'
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,11 +140,12 @@ 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 duration',
144
- name: 'foo',
145
- type: 'duration',
143
+ message: 'a metric foo=10.0',
144
+ name: 'foo',
146
145
  value: 10.0,
147
- timestamp: "2011-11-11T10:11:21.000Z"
146
+ timestamp: "2011-11-11T10:11:21.000Z",
147
+ type: 'metric',
148
+ severity: 'info'
148
149
  )
149
150
  expect(instance).to receive(:emit).with(expected_event)
150
151
  Log.measure(name: 'foo') do
@@ -160,13 +161,14 @@ describe Betterlog::Log do
160
161
 
161
162
  it 'adds exception information if block raises' do
162
163
  expected_event = Log::Event.new(
163
- name: 'foo',
164
- type: 'duration',
164
+ name: 'foo',
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',
168
168
  error_class: 'MyEx',
169
- backtrace: %w[ backtrace ]
169
+ backtrace: %w[ backtrace ],
170
+ type: 'metric',
171
+ severity: 'info'
170
172
  )
171
173
  expect(instance).to receive(:emit).with(expected_event)
172
174
  raised = false
@@ -184,39 +186,41 @@ describe Betterlog::Log do
184
186
  end
185
187
 
186
188
  describe '#metric' do
187
- it 'logs metrics with a specific structure on debug log level' do
189
+ it 'logs metrics with a specific structure on info log level' do
188
190
  expected_event = Log::Event.new(
189
- message: 'a metric controller.action of type ms',
190
- name: 'controller.action',
191
- type: 'ms',
192
- value: 0.123,
191
+ message: 'a metric controller.action=0.123',
192
+ name: 'controller.action',
193
+ value: 0.123,
194
+ type: 'metric',
195
+ severity: 'info'
193
196
  )
194
197
  expect(instance).to receive(:emit).with(expected_event)
195
- Log.metric(name: 'controller.action', type: 'ms', value: 0.123)
198
+ Log.metric(name: 'controller.action', value: 0.123)
196
199
  end
197
200
 
198
201
  it 'logs metrics on a given log level' do
199
202
  expected_event = Log::Event.new(
200
- message: 'a metric controller.action of type ms',
201
- name: 'controller.action',
202
- type: 'ms',
203
- value: 0.123,
203
+ message: 'a metric controller.action=0.123',
204
+ name: 'controller.action',
205
+ value: 0.123,
206
+ type: 'metric',
204
207
  severity: :info,
205
208
  )
206
209
  expect(instance).to receive(:emit).with(expected_event)
207
- Log.metric(severity: :info, name: 'controller.action', type: 'ms', value: 0.123)
210
+ Log.metric(severity: :info, name: 'controller.action', value: 0.123)
208
211
  end
209
212
 
210
213
  it 'logs metrics with additional data' do
211
214
  expected_event = Log::Event.new(
212
- message: 'a metric controller.action of type ms',
213
- foo: 'bar',
214
- name: 'controller.action',
215
- type: 'ms',
216
- value: 0.123,
215
+ message: 'a metric controller.action=0.123',
216
+ foo: 'bar',
217
+ name: 'controller.action',
218
+ value: 0.123,
219
+ type: 'metric',
220
+ severity: 'info'
217
221
  )
218
222
  expect(instance).to receive(:emit).with(expected_event)
219
- Log.metric(name: 'controller.action', type: 'ms', value: 0.123, foo: 'bar')
223
+ Log.metric(name: 'controller.action', value: 0.123, foo: 'bar')
220
224
  end
221
225
  end
222
226
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: betterlog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - betterplace Developers